Alex Gordon
Alex Gordon

Reputation: 60711

SQL Server: need to add a primary key

I have about 5000 records in a table in SQL Server 2008

I need to add a primary key. I don't care what it is, maybe an autonumber would be best?

How do I add a primary key to every record ?

I also would like this primary key to be generated automatically when I add new rows!

Upvotes: 3

Views: 156

Answers (1)

Abe Miessler
Abe Miessler

Reputation: 85046

Try this:

ALTER TABLE myTable ADD id INT IDENTITY
CONSTRAINT id _pk PRIMARY KEY;

Upvotes: 3

Related Questions