primary key fields
Database
2
Posts
2
Posters
0
Views
1
Watching
-
In a table how to check only primary key fields are there or not Please help me. Thanks in Advance, Pothirajan C
-
In a table how to check only primary key fields are there or not Please help me. Thanks in Advance, Pothirajan C
Pothirajan C wrote: In a table how to check only primary key fields are there or not I'm not sure what you mean. Do you mean: How do I check if a table contains a primary key or not?
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'Orders'
AND CONSTRAINT_TYPE = 'PRIMARY KEY')
BEGIN
-- The primary key exists
END
ELSE
BEGIN
-- The primary key does not exist
END
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More