Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

A place to share commonly used scripts for SQL Server Database Administrators.

Moderators

SQL Server DBA Scripts

Script to create a primary key on existing table in SQL Server

Mar 19 2012 12:00AM by Paresh Prajapati   

We are mostly creating primary key on column while creating tables, But sometime we also need to have it after creating table or on existing table as per need, So i am sharing the script to add primary key on table.

We can create a primary key on table with two options like i mentioned in the code below,

-- Option #1
ALTER TABLE TableName 
ADD PRIMARY KEY (ColumnName)
GO

-- Option #2
ALTER TABLE TableName
ADD CONSTRAINT PK_TableName_ColumnName PRIMARY KEY(ColumnName)
GO

In option #1 constraint will be created with default name as per system and in option #2 constraint will be created with the same name which we have mentioned.


Paresh Prajapati
6 · 23% · 7441
6
 
1
 
0
Failed
 
 
 
0
Unwise



Submit

Your Comment


Sign Up or Login to post a comment.

"Script to create a primary key on existing table in SQL Server" rated 5 out of 5 by 6 readers
Script to create a primary key on existing table in SQL Server , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]