1.查詢數(shù)據(jù)庫中的所有數(shù)據(jù)庫名:
SELECT ?Name ?FROM ?Master..SysDatabases ?ORDER BY ?Name
使用如下:
查詢所有數(shù)據(jù)庫名:

查詢所有數(shù)據(jù)庫名
查詢名稱中包含‘APP’的所有數(shù)據(jù)庫:

名稱包含'APP'的數(shù)據(jù)庫
2.查詢某個數(shù)據(jù)庫中所有的表名:
SELECT ?Name ?FROM ?SysObjects ?Where ?XType='U' ?ORDER ?BY ?Name
使用如下:
查詢數(shù)據(jù)庫中的所有表名:

查詢所有表名
查詢數(shù)據(jù)庫表名中包含某個字段的所有表

包含‘System’的所有表名
3.我們有時候會需要查詢數(shù)據(jù)庫中包含某字段的所有的表,去進(jìn)行update,這時就可以用下面的SQL來實(shí)現(xiàn):
select object_name(id) objName,Name as colName
from syscolumns
where (name like'%此處寫需要查詢的字段名稱%')
and id in(select id from sysobjects where xtype='u')
order by objname
使用效果:

查詢所有包含Password字段的表
;