views:

48

answers:

3

Hi

am new in asp.net , i want create tables in sql server 2008, actually i dont know how to create composite primary key.CAN ANYBODY HELP ME .Advance in thanks

+2  A: 
create table my_table (
     column_a integer not null,
     column_b integer not null,
     column_c varchar(50),
     primary key (column_a, column_b)
);
Thilo
thanks, its works Thilo
Ganesamoorthy
+1  A: 
CREATE TABLE UserGroup
(
  [User_Id] INT NOT NULL,
  [Group_Id] INT NOT NULL

  CONSTRAINT PK_UserGroup PRIMARY KEY NONCLUSTERED ([User_Id], [Group_Id])
)
Matthew Abbott
its works, thanks Matthew Abbott
Ganesamoorthy
A: 

Via Enterprise Manager...

  • Right Click on the Table you wish to create the composite key on and select Design.
  • Highlight the columns you which to form as a composite key
  • Right Click over those columns and Set Primary Key

To see the SQL you can then right click on the Table > Script Table As > Create To

kevchadders
its works, thanks kevchadders
Ganesamoorthy