SQLSERVER查询当前数据中的所有表

--切换数据库
use c2
go


--查询当前数据库表名
select [name] from sysObjects where xtype='U' and [name] <> 'dtproperties' order by[name]


--查询当前数据库所有用户视图
Select [name] From sysObjects Where xtype='V' And [name]<>'syssegments' And [name]<>'sysconstraints' Order By [name]


--获得指定表中所有的列和类型
Select
c.name As '列名',
t.name As '列类型'
From syscolumns c, systypes t, sysobjects o
Where c.xtype = t.xusertype
And c.id = o.id
And o.name='base_dict' --指定表名
Order By c.colorder




--获取当前数据库指定列名在那些表中 [ 在修改数据库中的某个字段,但这个字段又有关联其他表,用这种方式一幕了然就能看出哪张表用了我这个字段 ]
Select
m.name AS '表名',
c.name As '列名',
t.name As '列类型'
From syscolumns c, systypes t, sysobjects o , ( select [name] from sysObjects where xtype='U' and [name] <> 'dtproperties' ) m
Where c.xtype = t.xusertype
And c.id = o.id
And o.name =m.name
And c.name='product_id'  --指定列名
Order By m.name




--获取当前数据库所有表列名和表类型
Select
m.name AS '表名',
c.name As '列名',
t.name As '列类型'
From syscolumns c, systypes t, sysobjects o , ( select [name] from sysObjects where xtype='U' and [name] <> 'dtproperties' ) m
Where c.xtype = t.xusertype
And c.id = o.id
And o.name =m.name
Order By m.name
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值