Solved

SQl Random Number Generation and Audit Changes

Posted on 2012-03-15
4
239 Views
Last Modified: 2012-03-15
Hello,

1)  I am using the NewID() to generate the random numbers for one column in sql database table. Does it check for the uniqueness in the database table? This is how I am generating the random number and in the table the column's datatype is given as int.

ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT))

2) On my WebPage, if user edits something, I want to keep track of old data and new data as well. So, What I am doing is , I am just inserting a new record in to the table. Is there any other best way to do this? Something like audit, Which will have everything in it, like what was changed and when was it changed?

Thanks
0
Comment
Question by:shahjagat
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 37726073
>> Does it check for the uniqueness in the database table? <<

Not unless you explicitly create a constraint or an index.  SQL does not by default check any column for uniqueness.



>> Which will have everything in it, like what was changed and when was it changed? <<

In SQL 2008 you can use Change Data Capture (cdc).
0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
ID: 37726123
this is fine

ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT))

but you may get same numbers (low probability but possible)

use auto number... don't create random number...
0
 

Author Comment

by:shahjagat
ID: 37726919
Scott,

Thanks for the Information. I tried using the CDC to track all the changes. After i enabled the CDC, i made some changes and i am having a problem when i am checking the logs. I posted a question. Can you see the link below.

0
 

Author Comment

by:shahjagat
ID: 37726921
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question