Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 field not allowing duplicates

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-05 : 06:29:59
in sql management express how do i indicate a field that does not allow duplicates?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-05 : 06:51:26
Make field non-null and add UNIQUE constraint on the field.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-05 : 07:01:29
how do i do this in management express?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-08 : 02:11:28
can you tell me the syntax to do this -- to change the field to have a unique constraint
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:18:37
[code]-- to make field Non-Nullable
alter table <table-name>
alter column <column-name> <data-type> not null
GO

-- to add unique constraint
alter table <table-name>
add constraint <constraint-name> unique(<column-name>)
GO
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-08 : 02:25:50
what should be the constraint name or does it not matter?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:30:20
You can give any descriptive name or it may depend upon your company's naming standards.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -