SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MSSQL with Multiple Key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Gerald30
Starting Member

Philippines
49 Posts

Posted - 10/10/2012 :  21:43:07  Show Profile  Reply with Quote
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)

Singapore
17587 Posts

Posted - 10/10/2012 :  21:48:05  Show Profile  Reply with Quote
ID is the primary key in the table ?


KH
Time is always against us

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 10/11/2012 :  00:30:32  Show Profile  Reply with Quote
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

Edited by - bandi on 10/11/2012 00:32:26
Go to Top of Page

Gerald30
Starting Member

Philippines
49 Posts

Posted - 10/11/2012 :  05:32:17  Show Profile  Reply with Quote
Thank you very much guys.

ID is the PK so I use the composite unique.


Thanks again
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 10/11/2012 :  05:55:06  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000