0% found this document useful (0 votes)
180 views7 pages

DBA Stackexchange Com Questions 12360 What Is The Optimal Wa

Dba

Uploaded by

Mashhood Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views7 pages

DBA Stackexchange Com Questions 12360 What Is The Optimal Wa

Dba

Uploaded by

Mashhood Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Questions Tags Users Badges Unanswered Ask Question

_
Database Administrators Stack Here's how it works:
Exchange is a question and answer site
for database professionals who wish to
improve their database skills and learn
from others in the community. Join them;
it only takes a minute:
Anybody can ask Anybody can The best answers are voted
a question answer up and rise to the top
Sign up

What is the optimal way to design an approval queue and audit trail for entities in SQL Server 2008
R2?

asked 5 years, 11 months ago

viewed 2,359 times

active 5 years, 11 months ago

Simplified Explanation: I have three main tables: customer, phone, and customer_phone to
Related
resolve the many-to-many. I need to ensure that only admins can insert/update these tables without
approval. Everyone else needs to have their stuff go into an approval queue so admins can 5 Is there a non-DDL way to preserve back-
5 approve it. The admin needs to see the current value(s) and the proposed changes before references when staging data into production?
approving/denying. The system should log who submitted the information, and who approved it
5 Which is quicker: Select of existing row vs

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
(when applicable) in an audit trail, as well as anyone who modified it. The current approach Update where no row exists?
employed has three tables for every entity: 1 Why is replication attempting to distribute
NULL values into Identity columns
1
1. Main entity table
0 Create an Audit trail on SQL Server 2008 to
2. Holding table for unapproved records trace all privilege users
3. Audit log table for each entity 1 Normalization: Should common columns of two
tables be pulled out into a third table?
I think there should be some kind of simpler solution to this. The current system has problems
when: 2 Datawarehouse - Dimension, Fact, or
Degenerative dimension
An admin tries to approve an entity before the main entity is approved that it is linked to
0 Table design for optimum performance
The record already exists in the database but linking it to another record needs to be approved
1 self referencing tables with SQL and entity
This seems like a less-than-optimal solution to me. Is there a better way? framework

1 Inserts/updates are extremely slow with Merge


Lengthier Explanation: Here's a simplified view of the scenario: I have a primary entity and Replication in SQL Server 2008
secondary entities linked to it via linking tables. Admins can simply add/edit any entity at will, but
standard users must get approval from admins before their changes take effect. The problem is 1 Dropping old and creating a new clustered
index
that sometimes when a standard user enters a primary entity and linked entities, the admin must
approve the primary entity before linked ones can take effect. I want the admins to be able to see
Hot Network Questions
the old value and the proposed new value before approving, and I want to ensure they approve the
primary entity first. For example, let's assume we have the following tables below, and customer is Why is TV static noise always black and white?
the primary entity, phone is the secondary entity, then there is a linking table to resolve the many-
Professional ways of saying "Keep me in the loop
to-many relationship: in case you have some other projects I may be
able to contribute to"
CREATE TABLE [dbo].[customer](
[Customer_ID] [int] NOT NULL, Overlapping/Comparing two files and printing what
didn't match
[Customer_Name] [varchar](255) NOT NULL,
PRIMARY KEY CLUSTERED ([Customer_ID] ASC) How to specify justification of contents in
`amsmath`'s `align` environment?
CREATE TABLE [dbo].[phone](
[Phone_ID] [int] NOT NULL, How to get my 4yo daughter's fixation on my belly
button under control?
[Phone_Number] [int] NOT NULL,
PRIMARY KEY CLUSTERED ([Phone_ID] ASC) What is armor's durability?

CREATE TABLE [dbo].[customer_phone]( How do appreciate people's creations that take


[Customer_Phone_ID] [int] NOT NULL, very little effort
[Customer_ID] [int] NOT NULL, Lines run over PDF boundaries?
[Phone_ID] [int] NOT NULL,

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
[Approved] [char](1) NOT NULL, --Y/N How is the message "Unsupported CPU installed"
PRIMARY KEY CLUSTERED ([Phone_ID] ASC) displayed?

The Galactic Cold War


Now only an admin can add a customer or a phone number without approval. If a standard user
wants to add someone, it goes into a holding table. This is how that currently looks in my system. In Responding to being told to "smile" by a stranger?

addition to the above tables: Should I use the real name or attempt to describe?

CREATE TABLE [dbo].[customer_holding]( When did the phrase "above your paygrade" come
[Customer_ID] [int] NOT NULL, into use?
[Customer_Name] [varchar](255) NOT NULL, display STDOUTs before STDERR?
[Standard_User_ID] [int] NOT NULL, --who added record
PRIMARY KEY CLUSTERED ([Customer_ID] ASC) What feature film had a giant metal military statue
which moved, in front of a building?
CREATE TABLE [dbo].[phone_holding](
How powerful a microscope could my
[Phone_ID] [int] NOT NULL,
pyromancers make?
[Phone_Number] [int] NOT NULL,
[Standard_User_ID] [int] NOT NULL, --who added record Gigabit USB ethernet running at 100mb/s
PRIMARY KEY CLUSTERED ([Phone_ID] ASC)
Why would an army train living soldiers when
manufacturing robots is easier
Programatically standard users' submissions go to the holding table until an admin approves them.
But then I also need an audit log for the user who submitted the original record plus who approved Does ETH and ETC uses the same network ID?
the record and updates to it. The current system accomplishes this with a third auditing table for Write numbers as a difference of Nth powers
each record:
Does Ubuntu 17.10 break the BIOS?
CREATE TABLE [dbo].[customer_audit](
Do I add negative ability scores to skills?
[Customer_ID] [int] NOT NULL,
[User_ID] [int] NULL, Why isn't stripping wires by burning with a lighter a
[When_Approved] [datetime] NOT NULL, more common practice?
[Approved] [char](1) NOT NULL, --Y/N
PRIMARY KEY CLUSTERED ([Customer_ID] ASC) Are these chords the same?

CREATE TABLE [dbo].[phone_audit](


[Phone_ID] [int] NOT NULL,
[User_ID] [int] NULL,
[When_Approved] [datetime] NOT NULL,
[Approved] [char](1) NOT NULL, --Y/N
PRIMARY KEY CLUSTERED ([Phone_ID] ASC)

CREATE TABLE [dbo].[customer_phone_audit](


[Customer_Phone_ID] [int] NOT NULL,
[User_ID] [int] NULL,

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
[Action_Performed] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED ([Phone_ID] ASC)

Essentially every entity table has a holding table and an audit table for actions associated with that
entity. This seems redundant and problematic to me, although the current system does mostly work
using this design. I think there should be some kind of simpler solution to this. The current system
has problems when:

1. An admin tries to approve the phone before the customer is approved that it is linked to
2. The phone number already exists in the database but linking it to another customer needs to
be approved

It seems that these problems could be resolved through better design. What could be done better?
Three tables for every entity seems redundant to me, is there a better way? Thanks,

sql-server-2008 best-practices

share improve this question asked Feb 6 '12 at 21:23


Dan
207 3 14

add a comment

1 Answer active oldest votes

You could greatly simplify this by adding a few fields to your existing tables.

Add:
5 ChangeDate - smalldatetime that indicates when a record was added

Active - BIT

ChangeBy - user who added the record

ApprovedBy - admin who OKd the record

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You keep all your old records, so an update is really just a new row followed by changing the
ACTIVE bit to off for the old record and on for the new one. Your audit trail is built into your data.

The views that you use to expose the data can filter on the ACTIVE bit so no unapproved changes
are sent out. It will also assist in conflict resolution since EVERY proposed change has a row. If two
users propose a change the admin can choose one to accept, or make a new entry consolidating
them.

share improve this answer answered Feb 6 '12 at 21:30


JNK ♦
14.9k 5 46 88

Yes, but what about maintaining a historical record of who originally created the record and all updates since?
Also, what about when someone edits an existing record and the changes are not yet approved? I want the
original approved record to continue showing until the changes are approved by an admin. – Dan Feb 6 '12
at 21:37

Every update is it's own row. So the MIN(created) for a record will be the "original" – JNK ♦ Feb 6 '12 at
21:38

But how will all the other items linked to it remain linked once the update is approved? The links are all
maintained in separate tables, and there are actually A LOT of linking tables. Customer can be linked to one or
many phones, addresses, orders, etc.? Pardon my questions, just trying to figure this out. Would I have to
programatically update the links in all those tables every time an update is applied? Seems like a lot of
opportunity for errors. – Dan Feb 6 '12 at 21:44

Or do updates get written to the original record, and then the temp update record gets deleted? – Dan Feb 6
'12 at 21:45

It'll depend on how you want to set it up. Come to chat: chat.stackexchange.com/rooms/179/the-heap – JNK ♦
Feb 6 '12 at 21:46

show 3 more comments

Your Answer

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Sign up or log in Post as a guest

Sign up using Google Name

Sign up using Facebook Email

required, but never shown


Sign up using Email and Password

Post Your Answer

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged sql-server-2008 best-practices or ask
your own question.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
question feed

DATABASE ADMINISTRATORS

Tour
Help
Chat
Contact
Feedback
Mobile

COMPANY

Stack Overflow
Stack Overflow Business
Developer Jobs
About
Press
Legal
Privacy Policy

STACK EXCHANGE NETWORK

Technology
Life / Arts
Culture / Recreation
Science
Other

Blog • Facebook • Twitter • LinkedIn


site design / logo © 2018 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2018.1.15.28396

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

You might also like