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

  • Home
  • SEARCH
  • 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 3240324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:04:20+00:00 2026-05-17T18:04:20+00:00

in SQL Server Management Studio (SSMS) 2008 R2 Dev on the table (because I

  • 0

in SQL Server Management Studio (SSMS) 2008 R2 Dev on the table (because I cannot ask without it)

--SET ANSI_NULL_DFLT_ON ON
create table B (Id int)

I create unique constraint

ALTER TABLE B
ADD CONSTRAINT IX_B
UNIQUE (ID)
WITH (IGNORE_DUP_KEY = ON)

SSMS shows that I do not have any constraint but have a key + index instead while context options (on right clicking) hint me to create (sorry, script) still constraint.

alt text
alt text

MAIN QUESTION:
What is a key here?
Why is it needed for this constraint?
Why is unique constraint called by key (and key by unique constraint)?
Sorry, again, why is key called by index? They seem to have the same name (though had I created without explicit name they would have called differently)…
Sorry, again…

COLLATERAL questions:
Which functionality is different between “unique constraint” vs. “unique index”? I searched today for a single difference (wanted to find 10) quite a time and could not find any.
In other words, what’s for (why) are concepts (or constructs) “unique constraint” and “unique index” are duplicated in SQL Server?

Bonus question (for those whom this question seemed too simple):
What is the sense in unique index (or in unique constraint) permitting dupes?

insert into B VALUES (1)
insert into B VALUES (1)
insert into B VALUES (1)


Update: Sorry Thanks, guys and ladies (bonus is withdrawn)
Update2: Was not there a difference between “unique index” and “unique constraint” in previous SQL Server (I vaguely recall that one of them did not permit NULL)?
Update3: Really, I was always pissed off (confused) by a “foreign key constraint” is called by “foreign key” while it is not a key and the key, foreign one is in another table, foreign one … and just found that this is universal confusion to rattle on it. At least, now I memorize that I should remember au contraire.

Update4:
@Damien_The_Unbeliever, thanks,
these are, at least, some hrooks to memorize confusion.

Though, some bewilderments:
Why are these candidates NOT NULL by default?

Initially I really wanted to insert much shorter script:

CREATE TABLE A(A INT UNIQUE);  

which produced:
alt text

WTF this “candidate” for PRIMARY and KEY has multiple identities syndrome, then?
Is not “UQ_” stand for Unique constraint in naming practices?

Now, scripting of this index UQ__A__3214EC262AA05119 produces nameless… not index … constraint(?!):

ALTER TABLE [dbo].[A] ADD UNIQUE NONCLUSTERED 
(
    [ID] ASC
)
WITH 
(    PAD_INDEX  = OFF, 
     STATISTICS_NORECOMPUTE  = OFF, 
     SORT_IN_TEMPDB = OFF,
     IGNORE_DUP_KEY = OFF,
     ONLINE = OFF,
     ALLOW_ROW_LOCKS  = ON,
     ALLOW_PAGE_LOCKS  = ON) 
ON 
[PRIMARY]

WTheF – How is unique index is identified as constraint? Where, by what

Scripting of key produces the same! again, constraint…
Why is it nameless? Why is it impossible to script as “modify” but only as “create”?!
This does not make sense!

Now if to execute the produced script, there are 2 dupes,
to execute once more – voila: 3 dupe “candidates”
alt text

Note: if to create the unique constraint by separate T-SQL statement with custom/manual name, as I made at the top, then scripting does not produce anonymous DML and, respectively, their execution does not permit multiplication of “candidates”

Strange candidates for primary keys, aren’t they? need to visit a shrink (with multiple identities symptoms)?

  • 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. Editorial Team
    Editorial Team
    2026-05-17T18:04:21+00:00Added an answer on May 17, 2026 at 6:04 pm

    A UNIQUE constraint is also known as a UNIQUE KEY constraint. Basically, there can be multiple KEYs for a table. One is selected (somewhat arbitrarily) to be the PRIMARY KEY for the table. Other keys are created as UNIQUE KEY constraints.

    As an implementation detail, a UNIQUE KEY constraint is implemented by placing a UNIQUE index on the same columns in the table. However, it is possible to create UNIQUE indexes on a table (via CREATE INDEX), without creating a UNIQUE constraint.

    UNIQUE constraints are similar to PRIMARY KEYs – they can be the target reference for a FOREIGN KEY constraint. A UNIQUE index, by itself, cannot be so referenced.

    In SSMS, PRIMARY KEY, UNIQUE, and FOREIGN KEY constraints will always show up under the “Keys” folder for a table. CHECK and DEFAULT constraints will show up under the “Constraints” folder

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

Sidebar

Related Questions

Sql Server Management Studio 2008 is not scripting table permissions even when I select
In SQL Server Management Studio 2008, if I log into a shared hosting provider
Using MS SQL Server Management Studio 2005 - To Restore a Database: Restore Database
I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the New
In MS SQL Server Management Studio 2005: If you have the setting Tools|Options|Scripting|Include IF
When using SQL Server Management Studio from SQL Server 2005, I can connect to
I usually do not use Sql Server Management Studio, I usually use Linqpad to
It seems like the generation of SQL scripts from the SQL Server Management Studio
I was wondering if there are any alternatives to Microsoft's SQL Server Management Studio?
Why are some keywords highlighted blue and some gray in SQL Server Management Studio?

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.