Re: MSSqlServer table/field information (Solved, kinda)
| From: | Chris Boget | Date: | Fri, 22 Apr 2005 16:03:04 +0000 |
| Subject: | Re: MSSqlServer table/field information (Solved, kinda) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-213673@lists.php.net to get a copy of this message | ||
> 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