Skip to content

Add a Primary Key To Your SQL DB

June 9, 2014
tags:

It comes up from time to time where you have a DB you need to work with and you notice that some bastard didn’t put a PK on it.

Heres a quick way to wedge that in without too much fuss.

ALTER TABLE Accounts ADD ID int identity(1,1) not null
GO
ALTER TABLE Accounts ADD CONSTRAINT pk_Accounts_ID primary key(ID)
GO

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: