Right click on the table and you will get the columns. Press control or Shift key and select the columns -> Right click and you can set the primary key.
To add additional columns in the set of columns forming the composite key, you can use the alter-add command. And to delete a column from the set of columns combined together to form the composite key, you can use the alter-drop command.
here is some code to do it:
-- Sample Table
create table myTable
(
Column1 int not null,
Column2 int not null
)
GO
-- Add Constraint
ALTER TABLE myTable
ADD CONSTRAINT pk_myConstraint PRIMARY KEY (Column1,Column2)
GO
I added the constraint as a separate statement because I presume your table has already been created.
create table my_table (
id_part1 int not null,
id_part2 int not null,
primary key (id_part1, id_part2)
)
In design mode (right click table select modify) highlight both columns right click and choose set primary key
Open up the table designer in SQL Server Management Studio (right-click table and select 'Design')
Holding down the Ctrl key highlight two or more columns in the left hand table margin
Hit the little 'Key' on the standard menu bar at the top
You're done..
:-)
Highlight both rows in the table design view and click on the key icon, they will now be a composite primary key.
I'm not sure of your question, but only one column per table may be an IDENTITY column, not both.
create table myTable
(
Column1 int not null,
Column2 int not null
)
GO
ALTER TABLE myTable
ADD PRIMARY KEY (Column1,Column2)
GO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With