Link to home
Start Free TrialLog in
Avatar of shahjagat
shahjagatFlag for United States of America

asked on

SQl Random Number Generation and Audit Changes

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
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
Avatar of shahjagat

ASKER

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.