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.
Author |
Topic |
Gerald30
Yak Posting Veteran
62 Posts |
Posted - 2012-10-10 : 21:43:07
|
Hello AllIts 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 Count1 Mark 12 Adrew 13 Mark 2Now 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] |
|
|
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 LogCountALTER 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 |
|
|
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 |
|
|
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 |
|
|
|
|
|