Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Add Primary /Unique constraint to existing table

Author  Topic 

MuffinMan
Posting Yak Master

107 Posts

Posted - 2003-08-15 : 10:49:17
Trying to set up Full Text Indexing on an existing table that does NOT have a Primary /Unique constraint defined. The table does indeed had a column that is unique (Contact_ID), but wasn't defined so at design time. This table is in a production system and has nearly five million records in it.

I need to write a script (must be a script -- cannot use Enterprise Managner) to add the Primary /Unique constraint without locking (NOCHECK?) the table.

I've looked at Alter Table, but can't seem to get the syntax correct.

Sample code: (does not work)
Alter Table MyTable
add unique constraint MyConstraint (Contact_ID) with NOCHECK

Thoughts?

mr_mist
Grunnio

1870 Posts

Posted - 2003-08-15 : 10:56:55
ALTER TABLE mytable ADD CONSTRAINT contstaintname PRIMARY KEY CLUSTERED ( field, field)

I think it will lock the table though, nocheck just says don't check rows for compliance with constraints.

-------
Moo. :)
Go to Top of Page
   

- Advertisement -