Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

When should I use a unique constraint instead of a unique index?

Asked by Anusha Acharya Apr 22, 2021 1.2K views 1 answer
Share

About this question

When I want a column to have distinct values, I can either use a constraint create table t1( id int primary key, code varchar(10) unique NULL ); go or I can use a unique index create table t2( id int primary key, code varchar(10) NULL ); go create unique index I_t2 on t2(code); Columns with unique constraints seem to be good candidates for unique indexes. Are there any known reasons to use unique constraints and not to use unique indexes instead?


Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.