Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

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 Answer

0 votes
by (40.7k points)
edited by

The SQL Server Constraints command will be as follows:

ALTER TABLE <tablename> ADD CONSTRAINT

            <constraintname> UNIQUE NONCLUSTERED

    (

                <columnname>

    )

Follow these steps, if you want to use the Database Diagram:

Step 1: Right-Click on the table and then select 'Indexes/Keys'

Step 2: Click the Add button to add the new index

Step 3: Enter the needful information in the Properties which you'll find on the right-hand side: the columns that you want to set it as Unique to Yes and give an appropriate name.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 16, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...