Answered by:
Unique Constraint

Question
-
How can we apply unique constraint on a column with varchar datatype so that duplicates in the same column are not allowed, like identity card numbers,Debit Cards etcSaturday, October 22, 2011 3:17 AM
Answers
-
DDL example:
ALTER TABLE dbo.MyTable ADD CONSTRAINT UN_MyTable_DebitCardNumber UNIQUE NONCLUSTERED (DebitCardNumber);
Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/- Proposed as answer by Warwick Rudd Saturday, October 22, 2011 12:14 PM
- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Saturday, October 22, 2011 3:33 AMAnswerer -
In additional, you can create UNIQUE Non clustered index on that column.
Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Sunday, October 23, 2011 10:43 AM -
Sure, you can add a constraint providing that you don't already have duplicates in this column.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Sunday, October 23, 2011 2:06 PMAnswerer
All replies
-
DDL example:
ALTER TABLE dbo.MyTable ADD CONSTRAINT UN_MyTable_DebitCardNumber UNIQUE NONCLUSTERED (DebitCardNumber);
Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/- Proposed as answer by Warwick Rudd Saturday, October 22, 2011 12:14 PM
- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Saturday, October 22, 2011 3:33 AMAnswerer -
In additional, you can create UNIQUE Non clustered index on that column.
Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Sunday, October 23, 2011 10:43 AM -
In additional, you can create UNIQUE Non clustered index on that column.
Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/Sunday, October 23, 2011 10:43 AM -
Sure, you can add a constraint providing that you don't already have duplicates in this column.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Marked as answer by Stephanie Lv Saturday, October 29, 2011 5:58 AM
Sunday, October 23, 2011 2:06 PMAnswerer