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

When to use a unique constraint instead of a unique index?

Asked by Ayushi Gupta Jul 19, 2021 1.4K 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? How to create unique index sql server?

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.