D
David Thielen
Hi;
I need to get all column descriptions from a table where a database
may have two tables with the same name but different schemas. How can
I do this? (And is there a simplier select to do this?)
Note see below for why GetSchema will not work.
To get all columns descriptions I use:
Version 8:
cmd.CommandText = "SELECT COLUMN_NAME,
sysproperties.[value] FROM INFORMATION_SCHEMA.COLUMNS LEFT OUTER JOIN
" +
"sysproperties ON sysproperties.id =
OBJECT_ID(INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA + '.' + " +
"INFORMATION_SCHEMA.COLUMNS.TABLE_NAME) AND sysproperties.smallid =
INFORMATION_SCHEMA.COLUMNS.ORDINAL_POSITION " +
"AND
sysproperties.name = 'MS_Description' WHERE
(OBJECTPROPERTY(OBJECT_ID(INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA " +
"+
'.' + INFORMATION_SCHEMA.COLUMNS.TABLE_NAME), 'IsMsShipped') = 0) AND
(TABLE_NAME = @p1)";
cmd.Parameters.Add(MakeParam("@p1",
table));
Version 9:
cmd.CommandText = "SELECT c.name AS
[Column Name], ex.value AS Description FROM sys.columns AS c INNER
JOIN " +
"sys.extended_properties AS ex
ON ex.major_id = c.object_id AND ex.minor_id = c.column_id AND ex.name
= " +
"'MS_Description' AND
ex.class_desc = 'OBJECT_OR_COLUMN' " +
"WHERE
(OBJECTPROPERTY(c.object_id, 'IsMsShipped') = 0) AND
(OBJECT_NAME(c.object_id) = @p1)";
cmd.Parameters.Add(MakeParam("@p1",
table));
I cannot use GetSchema() because:
1) Does not provide the description for a column.
2) Columns in a table are not returned in metadata order (which users
expect).
??? - thanks - dave
david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
I need to get all column descriptions from a table where a database
may have two tables with the same name but different schemas. How can
I do this? (And is there a simplier select to do this?)
Note see below for why GetSchema will not work.
To get all columns descriptions I use:
Version 8:
cmd.CommandText = "SELECT COLUMN_NAME,
sysproperties.[value] FROM INFORMATION_SCHEMA.COLUMNS LEFT OUTER JOIN
" +
"sysproperties ON sysproperties.id =
OBJECT_ID(INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA + '.' + " +
"INFORMATION_SCHEMA.COLUMNS.TABLE_NAME) AND sysproperties.smallid =
INFORMATION_SCHEMA.COLUMNS.ORDINAL_POSITION " +
"AND
sysproperties.name = 'MS_Description' WHERE
(OBJECTPROPERTY(OBJECT_ID(INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA " +
"+
'.' + INFORMATION_SCHEMA.COLUMNS.TABLE_NAME), 'IsMsShipped') = 0) AND
(TABLE_NAME = @p1)";
cmd.Parameters.Add(MakeParam("@p1",
table));
Version 9:
cmd.CommandText = "SELECT c.name AS
[Column Name], ex.value AS Description FROM sys.columns AS c INNER
JOIN " +
"sys.extended_properties AS ex
ON ex.major_id = c.object_id AND ex.minor_id = c.column_id AND ex.name
= " +
"'MS_Description' AND
ex.class_desc = 'OBJECT_OR_COLUMN' " +
"WHERE
(OBJECTPROPERTY(c.object_id, 'IsMsShipped') = 0) AND
(OBJECT_NAME(c.object_id) = @p1)";
cmd.Parameters.Add(MakeParam("@p1",
table));
I cannot use GetSchema() because:
1) Does not provide the description for a column.
2) Columns in a table are not returned in metadata order (which users
expect).
??? - thanks - dave
david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm