To check a primary key exists or not in table

Chikul
Posted by Chikul under Sql Server category on | Views : 2389
IF OBJECTPROPERTY( OBJECT_ID( '[dbo].[Employee]' ), 'TableHasPrimaryKey' ) = 1
PRINT '[dbo].[Employee] table has a primary key.'
ELSE
PRINT '[dbo].[Employee] table has no primary key.'

Comments or Responses

Login to post response