How to add and drop primary key in SQL Server

How to add and drop primary key in SQL Server

If you want to add primary key after you create the table in the sql server, then
1. go to Microsoft SQL Server Management Studio
2. Right click on the database and select new query
3. ALTER TABLE tbl_name ADD PRIMARY KEY(pr_key_column);
tbl_name – name of the table you want to assign primary key
pr_key_column – column/field name which you want it to be primary key

If the pr_key_column is allowed null values, then you can’t assign it as primary key. So if that is the case use this query first:
ALTER TABLE tbl_name ALTER COLUMN pr_key_column datatype not null;

To revoke primary key:
ALTER TABLE tbl_name DROP CONSTRAINT(pr_key_column);

See how you would solve these known algorithm problems

Array reversal in Recurrsion

Check if there are three numbers a, b, c giving a total T from array A

Find longest palindrom from sequence of characters

Finding missing numbers from billion sequential number list file

Find the first occurence of number in the sorted array

Find the pairs that makes K Complementary in the given array java solution

Changing decimal number to its binary equivalent

Java solution for checking anagram strings – tell if phrases are anagrams

Check if two strings are anagrams or not

Kadane’s algorithm in C – Dynamic Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*