You are here: Re: [PHP] MSSqlServer table/field information (Solved, kinda) « PHP « IT news, forums, messages
Re: [PHP] MSSqlServer table/field information (Solved, kinda)

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация