This is a simple tip post that may seem obvious and taken for granted for those of us who have been working with SQL Server for a while now but may be a newbie will find this helpful.
Here, I will give you a simple tip to check that primary is exists or not in table.
TO check primary key existence in table we have to use the following query. In the following query I have used MyTestTable as an example table. You have to change your table name from this table name.
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.'