t-sql autogenerate code

I have used following code to create unique id, if we deleted details is it possible to
come same number
NEWID()
LVL 10
ukerandiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
No, NEWID will always give you a new ID. You can't generate same ID again.
Easwaran ParamasivamCommented:
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 HornMicrosoft SQL Server Data DudeCommented:
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.
Scott PletcherSenior DBACommented:
NEWID() can in theory give you duplicate values.  It's extremely unlikely, but in theory it can happen, and MS makes no assurances that it won't.  Odds are, though, it won't happen in your lifetime, so it will be someone else's problem if it does :).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.