SQL Server 2005 How Create a Unique Constraint?
问题 How do I create a unique constraint on an existing table in SQL Server 2005? I am looking for both the TSQL and how to do it in the Database Diagram. 回答1: The SQL command is: ALTER TABLE <tablename> ADD CONSTRAINT <constraintname> UNIQUE NONCLUSTERED ( <columnname> ) See the full syntax here. If you want to do it from a Database Diagram: right-click on the table and select 'Indexes/Keys' click the Add button to add a new index enter the necessary info in the Properties on the right hand side: