Start Free Trial
t-sql autogenerate code
I have used following code to create unique id, if we deleted details is it possible to
come same number
Microsoft SQL Server
Microsoft SQL Server 2005
Microsoft SQL Server 2008
8/22/2022 - Mon
No, NEWID will always give you a new ID. You can't generate same ID again.
If you want to get the unique value always and wanted to get back the value then use date time functions such as getdate()
Vitor is correct in that the answer is 'No, you can't do that'.
If this is a hard business requirement to resurrect previously deleted NEWID() values, you may want to consider a 'soft delete' where there is a bit column named something like IsDeleted that contains a 1 for deleted rows and 0 for active rows. That way the record still exists even when 'deleted', and to make the row active again all you have to do is change IsDeleted back to 0.
Either that or build some kind of backup/restore strategy where rows marked as deleted are moved to another table/database/whatever, and there is functionality to make those rows active again by a separate process to access them which moves the row back.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
ASKER CERTIFIED SOLUTION
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Plans and Pricing
Certified Expert Program
© 1996-2023 Experts Exchange, LLC. All rights reserved. Covered by US Patent