26.7.08

To fetch all the constraints in SQL Server

Lets discuss one of the interesting features in SQL Server 2005 - Information_Schema.
Its a cool feature available in SQL Server 2005. Inorder to avoid direct access on the system tables. Microsoft have intoduced a layered structure to access the system related information. They have used views to achieve the same.
In the below query, I am trying to fetch all the Primary key and foreign key constriants available in the database.
Code Snippet
select CONSTRAINT_NAME,TABLE_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS

Happy Learning!!!

Regards,

Venkatesan prabu .J

No comments:

Post a Comment