Sunday, July 28, 2013

How To- Check Primary Key Exists or not in Table



 TO check primary key existence in table




IF OBJECTPROPERTY( OBJECT_ID( '[dbo].[MyTestTable]' ), 'TableHasPrimaryKey' ) = 1
   PRINT '[dbo].[MyTestTable] table has a primary key.'
ELSE
   PRINT '[dbo].[MyTestTable] table has no primary key.'
 

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More