Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 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.4k points)

The SQL 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
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...