如何用SQL语句查询一个数据表所有字段的类型

如何用SQL语句查询一个数据表所有字段的类型,第1张

用SQL语句查询一个数据表所有字段类型可以参考下面的代码:

SELECT

name AS column_name,TYPE_NAME(system_type_id) AS column_type,

max_length,is_nullable

FROM syscolumns

WHERE object_id=OBJECT_ID(N'Address')

扩展资料:

SQL语句

创建索引:create [unique] index idxname on tabname(col…。)

增加列:Alter table table_name add column_name column_type [default 默认值]--在表中增加一列,[]内的内容为可选项

删除索引:drop index idxname on tabname

参考资料来源:百度百科-结构化查询语言

SELECT syscolumnsname,systypesname,syscolumnslength

FROM syscolumns JOIN systypes ON syscolumnsxusertype=systypesxusertype

WHERE syscolumnsid=OBJECT_ID('COURSE')

或者

SELECT colname, typename,collength

FROM syscolumns col JOIN systypes type ON colxusertype= typexusertype

WHERE colid=OBJECT_ID('表名')

-- 两者都是一样的,只是添加了友好列名而已

-- OBJECT_ID(),系统自带的一个方法根据表明获得系统内表的ID号

-- syscolumnsname -- 列的名称

-- systypesname -- 列类型名

-- syscolumnslength -- 类型长度

---------------------------------------------------------------------------------------

或者用楼上的方法,调用系统自带的一个存储过程得到关于你想要表的所有信息

要从系统表中查询了。

select aname as [column],bname as type

from syscolumns a,systypes b

where aid=object_id('表名') and axtype=bxtype

把“表名”替换成你要查看字段类型的表名,比如你要查看sysobjects表的各字段类型那么就是

select aname as [column],bname as type

from syscolumns a,systypes b

where aid=object_id('sysobjects') and axtype=bxtype

另外可以通过存储过程

exec sp_help 表名

来查看表各字段的信息,其中就包括字段类型。

select from sysobjects 查询所有表

select

cname as tablename,

aname as colname,

bname as typename

from

syscolumns a,systypes b ,sysobjects c

where

axusertype=bxusertype

and aid=cid

order by cid

以上就是关于如何用SQL语句查询一个数据表所有字段的类型全部的内容,包括:如何用SQL语句查询一个数据表所有字段的类型、sql如何查某个表某个字段的数据类型、通过sql字段查类型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9341483.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存