0

I need to delete existing PK from table and create new in new column. Because column for new PK was added later (after table creation) - we have nulls for old rows. Should I use UPDATE statement or there is some option in "ADD CONSTRAINT" clause which automatically determine NULLs and generate GUIDs for them?

Thanks for help.

Roman Badiornyi
  • 1,509
  • 14
  • 28

1 Answers1

1

This is what you have to do.

UPDATE TABLE1
SET GUID = NEWID()
WHERE GUID IS NULL

Now to add a new contstraint, you will have tod elete the old one. This is how you can do it:

ALTER TABLE TABLE1
DROP CONSTRAINT PrimaryKeyName

ALTER TABLE TABLE1
ADD CONSTRAINT PrimaryKeyName PRIMARY KEY (GUID)
Praveen Nambiar
  • 4,852
  • 1
  • 22
  • 31