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
 Combination of 2 field will generate a primary key

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-07-18 : 00:19:54
Let's say i've this following table,

tblusertype
Usertype | RolesID
--------------------
IT Support | 1
IT Support | 2
Technician | 1
IT Support | 3
Technician | 2
.....
.....
.....

*There's no repetition value in combination of Usertype and RolesID.
*Combination of Usertype and RolesID field will generate a unique value (primary key).

How to make sure there's no repetion value in tblusertype? It is using rules or ??? in tblusertype design?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-18 : 02:42:53
[code]CREATE TABLE tblusertype
(
Usertype varchar(10),
RolesID int,
CONSTRAINT PK_tblusertype PRIMARY KEY (Usertype, RolesID)
)[/code]


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

Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-07-18 : 03:20:54
if using management studio, how to right click and ...??

The tblusertype already created. can you show me
the syntax in alter table?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-18 : 04:36:26
quote:
Originally posted by Delinda

if using management studio, how to right click and ...??

The tblusertype already created. can you show me
the syntax in alter table?


ALTER TABLE tblusertype ADD CONSTRAINT PK_tblusertype PRIMARY KEY (Usertype, RolesID)
Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2008-07-18 : 05:48:34
it's work. TQVM.
Go to Top of Page
   

- Advertisement -