Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top