Wednesday, May 30, 2012

Find list of primary keys in a database in sql server

Here i will show how to get the all list of existing primary key field's in data base in sqlserver.For this i have write a simple sql query to get constraint in tables.Here i have three table which are emp,Department,city.

Sql query:
USE [Test Krishna]

SELECT pk.TABLE_NAME AS TableName,

pk.CONSTRAINT_NAME AS PrimaryKeyFieldInTable FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk

WHERE pk.CONSTRAINT_TYPE ='PRIMARY KEY' 

1 comment:

Anonymous said...

Τhanκ you for the goοd writeuр. It in fact
ωas a amusement account it. Look aԁѵanced to far adԁed agreеаble
from уou! Ηowever, hoω cаn we сommunicate?
Also visit my website : Fish Oil

Bel