十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
-- 获取所有数据库名
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'
--所有触发器
select name from sysobjects where xtype='TR'
--所有存储过程
select name from sysobjects where xtype='P'
--所有视图
select name from sysobjects where xtype='V'
--所有表
select name from sysobjects where xtype='U'
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)