獲取所有數據庫名、表名、字段名
阿新 • • 發佈:2018-04-21
SQL
-- 獲取所有數據庫名
select name from master..sysdatabases where name = ‘Fly‘
-- 獲取所有表名
select name from Fly..sysobjects where xtype=‘U‘ order by name
--獲取字段名
SELECT COLUMN_NAME,DATA_TYPE FROM Fly.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME= ‘A‘
DECLARE
@DataBaseName nvarchar(100)
,@TableName nvarchar(100)
,@exec_Sql varchar(100)
set @DataBaseName = ‘Fly‘
set @TableName = ‘A‘
set @exec_Sql = ‘SELECT COLUMN_NAME,DATA_TYPE FROM ‘
+ @DataBaseName
+ ‘.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME= ‘
+ ‘‘‘‘ + @TableName +‘‘‘‘
exec(@exec_Sql)
獲取所有數據庫名、表名、字段名