how to find the primary key value is already exist or not

Posted by Ramakrishna188 under ASP.NET on 3/31/2012 | Points: 10 | Views : 4345 | Status : [Member] | Replies : 1
hi
how to find the primarykey value already exists or not in asp.net using c#




Responses

Posted by: T.Saravanan on: 4/1/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try the following query...


SELECT CONSTRAINT_NAME, TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
AND TABLE_NAME = '<Table Name>'


Refer the following link for get more info...
http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-primary-key-constraint-in-database/
http://www.codeproject.com/Articles/20600/Find-Primary-Key-or-ID-column-of-Table-in-SQL-Serv

Thanks,
T.Saravanan

Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response