[ Team LiB ] Recipe Retrieving Constraints from a SQL Server Database Problem You need to programmatically define constraints in a DataSet and retrieve constraint information defined in a SQL Server database. Solution Use the INFORMATION_SCHEMA views and SQL Server system tables to get information about primary keys, foreign keys, and check constraints. | Team LiB Recipe Retrieving Constraints from a SQL Server Database Problem You need to programmatically define constraints in a DataSet and retrieve constraint information defined in a SQL Server database. Solution Use the INFORMATION_SCHEMA views and SQL Server system tables to get information about primary keys foreign keys and check constraints. The sample code contains one event handler Get Constraints Uses a SQL select statement to load the specified constraint information primary key foreign key or check constraint from the INFORMATION_SCHEMA views into a DataTable. The C code is shown in Example 6-27. Example 6-27. File Namespaces variables and constants using System using using using using private const String GETPRIMARYKEYCONSTRAINTS SELECT FROM tc JOIN kcu ON WHERE PRIMARY KEY ORDER BY private const String GETFOREIGNKEYCONSTRAINTS SELECT ParentTable ChildTable ParentColumn ChildColumn FROM rc LEFT JOIN kcuP ON LEFT JOIN kcuC ON AND ORDER BY private const String GETCHECKCONSTRAINTS SELECT FROM tc JOIN cc ON WHERE CONSTRAINT_TYPE CHECK .