SQL语句获取所有数据库名、表名、字段名、表字段长度

获取数据库中所有的表
SELECT SysObjects.name AS Tablename FROM sysobjects WHERE xtype = 'U'

获取数据库中所有表的列名
SELECT SysColumns.name AS Columnsname, SysObjects.name AS Tablename FROM SysObjects, SysColumns WHERE Sysobjects.Xtype='u' AND Sysobjects.Id=Syscolumns.Id


获取SQL所有数据库名、所有表名、所有字段名、表字段长度
1.获取MSSQL中的所有数据库名:
SELECT name FROM MASter..SysDatabASes ORDER BY name


2.获取MSSQL中的所有用户表名:
SELECT name FROM DatabASename..SysObjects WHERE XType='U' ORDER BY name
XType='U':表示所有用户表;
XType='S':表示所有系统表;


3.获取指定表[tb_phone]的所有字段名:
SELECT name FROM SysColumns WHERE id=Object_Id('tb_phone')


4.SQL所有表的表名、所有字段名、表字段长度
SELECT table_name AS 数据表名,
column_name AS 字段名,
ISNULL(column_default,'') AS 默认值,
is_nullable AS 是否允许为NULL,
data_type AS 数据类型,
ISNULL(ISNULL(ISNULL(character_maximum_length,numeric_precision),datetime_precision),1) AS 类型长度
FROM information_schema.columns
WHERE NOT table_name IN('sysdiagrams','dtproperties')


5.获取指定表[tb_phone]的表名,表字段名,字段类型和类型长度
SELECT SysObjects.name AS Tablename,
Syscolumns.name AS Columnsname,
Systypes.name AS DateType,
Syscolumns.length AS DateLength
FROM Sysproperties RIGHT OUTER JOIN
Sysobjects INNER JOIN
Syscolumns ON Sysobjects.id = Syscolumns.id INNER JOIN
Systypes ON Syscolumns.xtype = Systypes.xtype ON
Sysproperties.id = Syscolumns.id AND
Sysproperties.smallid = Syscolumns.colid
WHERE (Sysobjects.xtype = 'u' OR
Sysobjects.xtype = 'v') AND (Systypes.name <> 'Sysname') AND
(Sysobjects.name = 'tb_phone')
ORDER BY Columnsname
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值