如何在整个数据库里查询出包含特定字段名的表名
现有MSSQL数据库名为“test”,该库有数百个表,需要实现的目的为:在该数据的所有表中查询出字段名“成绩”的表名,请问该如何写,
select a.name as 表名 from sysobjects a left join syscolumns b on a.id=b.id where a.xtype='U'EXCEPTselect a.name as 表名 from sysobjects a left join syscolumns b on a.id=b.id where a.xtype='U' and b.name like '%成绩%'
select a.name as 表名 from sysobjects a where a.xtype='U' and not exists(select 1 from syscolumns b where a.id=b.id and b.name<>'成绩')
|