Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQl Random Number Generation and Audit Changes

Posted on 2012-03-15
4
Medium Priority
?
247 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 70

Accepted Solution

by:
Scott Pletcher earned 1000 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 61

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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