Posted by Chris Boget on 04/22/05 19:03
> Look into the INFORMATION SCHEMA views in SQL Books Online for a
> starting point.
Excellent tip! Thanks. With the help provided by everyone who
replied, I came up with the following:
Query to get the primary key(s) for a table
sp_pkeys @table_name='<table_name>'
Query to get the column names for a table
sp_columns @table_name='<table_name>'
Query to get the constraints on the columns of the table
SELECT
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.COLUMN_NAME,
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.CONSTRAINT_NAME,
INFORMATION_SCHEMA.CHECK_CONSTRAINTS.CHECK_CLAUSE
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
INNER JOIN
INFORMATION_SCHEMA.CHECK_CONSTRAINTS ON
INFORMATION_SCHEMA.CHECK_CONSTRAINTS.CONSTRAINT_NAME =
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.CONSTRAINT_NAME
WHERE
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.TABLE_NAME =
N'<table_name>'
thnx,
Chris
[Back to original message]
|