Solved

SQl Random Number Generation and Audit Changes

Posted on 2012-03-15
4
234 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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
TSQL mapping detailed records to group records 9 26
Record extraction 3 12
getting id from database 5 24
ASP.NET reading ATOM 2 22
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

11 Experts available now in Live!

Get 1:1 Help Now