I have used following code to create unique id, if we deleted details is it possible to
come same number
NEWID()
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008
Last Comment
Scott Pletcher
8/22/2022 - Mon
Vitor Montalvão
No, NEWID will always give you a new ID. You can't generate same ID again.
Easwaran Paramasivam
If you want to get the unique value always and wanted to get back the value then use date time functions such as getdate()
Jim Horn
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.