Define Unique Key in SQL Server

How to define unique key in table? Is it possible to define one primary key and one unique key in a single table?

Questions by kathiravan_g

Showing Answers 1 - 6 of 6 Answers

cybersavvy

  • Feb 19th, 2009
 

Yes, its possible to have PRIMARY KEY and UNIQUE keys in the same table on different columns.

UNIQUE key constraint allows the column to have distinct & one NULL values.

  Was this answer useful?  Yes

pavan

  • Jul 27th, 2011
 

If a column allows the duplication once is known as a unique key.i.e; Unique Key allows duplication once.But, Primary Key will not allow duplication.

Code
  1.  

  Was this answer useful?  Yes

erik

  • Jul 21st, 2012
 

SQL UNIQUE key...

The UNIQUE constraint uniquely identifies each record in a database table.

The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.

A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.

Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

SQL UNIQUE Constraint on CREATE TABLE

The following SQL creates a UNIQUE constraint on the "P_Id" column when the "Persons" table is created:

SQL:


Code
  1.  



SIMILARLY OTHERS

Code
  1. span style="color: #ff0000;">"P_Id""Persons"

  Was this answer useful?  Yes

asifeqbal

  • Mar 19th, 2015
 

UNIQUE key constraint enforce uniqueness of the column on which they are defined. It allows the column to have distinct & one NULL values. We can make one or more columns unique in a table by defining a UNIQUE NONCLUSTERED index on the column.
It is Possible to define Primary key and Unique key in the same table on different columns.

Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions