Question

I have set newid() to many tables as primary key, which is also refereed as foreign key at various places.

is it safe to convert nweid() to uniqueidentifier?

is there any chances of datalost?

Was it helpful?

Solution

You don't actually convert, NEWID() returns an uniqueidentifier:

NEWID (Transact-SQL)

Creates a unique value of type uniqueidentifier.

A separate note, though: Be wary of using uniqueidentifiers as primary keys if you do not have a separate clustered index. Since uniqueidentifiers are not sequential, your inserts will have worse performance than if using a sequentially incrementing key.

OTHER TIPS

It is impossible to convert newid () to uniqueidentifier because IT ALREADY IS ONE. So there is no conversion.

If you read the documentation:

http://technet.microsoft.com/en-us/library/ms190348.aspx

it says:

Return Types uniqueidentifier

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top