Solved

SQl Random Number Generation and Audit Changes

Posted on 2012-03-15
4
235 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:
ScottPletcher 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:HainKurt
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now