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)
 how to make 2 UNIQUE fields in a table

Author  Topic 

LearningIT
Starting Member

5 Posts

Posted - 2010-06-09 : 04:38:28
i am using MS SQL Server 2005 with Management Studio.

I have an employee table contains following fields

EmployeeId [PK, IDENTITY Column]
EmployeeCode
EmployeeName
DOB
CNIC
Gender
MaritalStatus

I need to create EmployeeCode also a unique field so that no duplication employee codes can be entered in the table. because this is the rule that each employee will have only one Employee Code.

Can anyone help me ? I'd be thankful.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-06-09 : 04:42:31
ALTER TABLE employee ADD CONSTRAINT unq_k UNIQUE (EmployeeCode)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-09 : 04:42:54
Create a unique constraint on EmployeeCode

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-09 : 04:43:28


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

LearningIT
Starting Member

5 Posts

Posted - 2010-06-09 : 08:31:29
Thankyou all, problem has been fixed with you valuable help. :-)
Go to Top of Page
   

- Advertisement -