D
David Thielen
Hi;
To get all columns from Sql Server I use:
cmd.CommandText = "SELECT COLUMN_NAME, DATA_TYPE from
INFORMATION_SCHEMA.COLUMNS where table_name=@p1";
But how can I do this if I have a schema.table and there are 2
identically named tables in the database?
Same question for getting FKK mappings (I use):
cmd.CommandText = "SELECT fc.name AS foreign_column_1,
fc2.name AS foreign_column_2, p.name AS primary_table, " +
"rc.name AS primary_column_1, rc2.name AS
primary_column_2 FROM sys.sysobjects AS f INNER JOIN " +
"sys.sysobjects AS c ON f.parent_obj = c.id INNER
JOIN sys.sysreferences AS r ON f.id = r.constid INNER JOIN " +
"sys.sysobjects AS p ON r.rkeyid = p.id INNER JOIN
sys.syscolumns AS rc ON r.rkeyid = rc.id AND " +
"r.rkey1 = rc.colid INNER JOIN sys.syscolumns AS
fc ON r.fkeyid = fc.id AND r.fkey1 = fc.colid LEFT OUTER JOIN " +
"sys.syscolumns AS rc2 ON r.rkeyid = rc2.id AND
r.rkey2 = rc.colid LEFT OUTER JOIN sys.syscolumns AS fc2 ON " +
"r.fkeyid = fc2.id AND r.fkey2 = fc.colid WHERE
(f.type = 'F') AND (c.name = '" + sysTable + "')";
and column descriptions:
cmd.CommandText = "SELECT t.name AS [Table Name], ex.value AS
Description FROM " + sysTable +
" AS t,
sys.extended_properties AS ex WHERE ex.major_id = t.object_id AND
ex.minor_id=0 AND ex.name = 'MS_Description' ";
thanks - dave
david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
To get all columns from Sql Server I use:
cmd.CommandText = "SELECT COLUMN_NAME, DATA_TYPE from
INFORMATION_SCHEMA.COLUMNS where table_name=@p1";
But how can I do this if I have a schema.table and there are 2
identically named tables in the database?
Same question for getting FKK mappings (I use):
cmd.CommandText = "SELECT fc.name AS foreign_column_1,
fc2.name AS foreign_column_2, p.name AS primary_table, " +
"rc.name AS primary_column_1, rc2.name AS
primary_column_2 FROM sys.sysobjects AS f INNER JOIN " +
"sys.sysobjects AS c ON f.parent_obj = c.id INNER
JOIN sys.sysreferences AS r ON f.id = r.constid INNER JOIN " +
"sys.sysobjects AS p ON r.rkeyid = p.id INNER JOIN
sys.syscolumns AS rc ON r.rkeyid = rc.id AND " +
"r.rkey1 = rc.colid INNER JOIN sys.syscolumns AS
fc ON r.fkeyid = fc.id AND r.fkey1 = fc.colid LEFT OUTER JOIN " +
"sys.syscolumns AS rc2 ON r.rkeyid = rc2.id AND
r.rkey2 = rc.colid LEFT OUTER JOIN sys.syscolumns AS fc2 ON " +
"r.fkeyid = fc2.id AND r.fkey2 = fc.colid WHERE
(f.type = 'F') AND (c.name = '" + sysTable + "')";
and column descriptions:
cmd.CommandText = "SELECT t.name AS [Table Name], ex.value AS
Description FROM " + sysTable +
" AS t,
sys.extended_properties AS ex WHERE ex.major_id = t.object_id AND
ex.minor_id=0 AND ex.name = 'MS_Description' ";
thanks - dave
david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm