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
 General SQL Server Forums
 New to SQL Server Programming
 MSSQL with Multiple Key

Author  Topic 

Gerald30
Yak Posting Veteran

62 Posts

Posted - 2012-10-10 : 21:43:07
Hello All

Its me again, I don`t know if I can explain this right but how can I do this in MSSQL.

Example I have this Employee Log Table with the following columns.

ID Name Log Count
1 Mark 1
2 Adrew 1
3 Mark 2

Now when I will insert again the Name Mark with Log Count 1 database should not allow because it will be duplicate.

Please help me.

Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-10-10 : 21:48:05
ID is the primary key in the table ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-11 : 00:30:32
Hi,


1) If ID is primary key, then ALTER yourTable by adding composite unique key of Name and LogCount


ALTER TABLE EmployeeLog ADD CONSTRAINT Emp_UK UNIQUE(Name, LogCount)


2) If ID is not a Primary key column, then add composite primary key of Name and LogCount
--
Chandu
Go to Top of Page

Gerald30
Yak Posting Veteran

62 Posts

Posted - 2012-10-11 : 05:32:17
Thank you very much guys.

ID is the PK so I use the composite unique.


Thanks again
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-11 : 05:55:06
quote:
Originally posted by Gerald30

Thank you very much guys.

ID is the PK so I use the composite unique.


Thanks again



Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -