Re: MSSqlServer table/field information (Solved, kinda)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux