Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 70755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:46:51+00:00 2026-05-10T19:46:51+00:00

When creating an index over a column that is going to be UNIQUE (but

  • 0

When creating an index over a column that is going to be UNIQUE (but not the primary key of the table), SQL server let’s me choose a few options:

1) I can choose for it to be a Constraint or an Index.
I’m guessing this means that if I set it as constraint, it won’t use it when querying, only when writing. However, the only efficient way I can think of for SQL Server to enforce that constraint is by actually building an index. What is the use for this option?

2) Also, if I set it as ‘index’, it let’s me specify that it should ignore duplicate keys. This is the most puzzling for me…
I again guess it means the opposite of constraint. It probably means ‘use it when querying, but don’t even check when writing’.
But then why would I set it as UNIQUE?
I’m guessing there are some optimizations SQL Server can do, but i’d like to understand it better.

Does anyone know what exactly SQL Server does with these options?
What’s the use case for setting an index to be Unique, but ignore duplicate keys?

NOTE: This is for SQL Server 2000


EDIT: According to what you said, however… If I create a Constraint, will it be used to speed up queries that filter using the fields in the constraint?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:46:51+00:00Added an answer on May 10, 2026 at 7:46 pm

    A UNIQUE constraint is part of the ISO/ANSI SQL standard, whereas indexes are not because the Standard is implementation agnostic. SQL Server, in common with most SQL DBMSs, will use an index to implement a UNIQUE constraint.

    Arguably, using UNIQUE rather than index in a SQL script is slightly more portable but as always the proprietary syntax should not be ruled out if it provids opportunities for optimization etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating indexes for an SQL table,if i had an index on 2 columns
Is creating an index for a column that is being summed is faster than
I need help with creating a C# method that returns the index of the
Possible Duplicate: T-SQL Pivot? Possibility of creating table columns from row values I've been
I'm creating a function in C to convert an index value into a string,
I am having an issue with creating a splice for a weighted index. I
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a server-side socket will fail if I'm trying to use the same port
I am creating a temp table with a query like this: CREATE TEMPORARY TABLE
I am creating a 3d plane that lies on the x and z axis,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.