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
下面一段是SQLSERVER数据库中获取数据字典的语法,非常全。
SELECT TOP 100 PERCENT --aid,
CASE WHEN acolorder = 1 THEN dname ELSE '' END AS 表名,
CASE WHEN acolorder = 1 THEN isnull(fvalue, '') ELSE '' END AS 表说明,
acolorder AS 字段序号, aname AS 字段名, CASE WHEN COLUMNPROPERTY(aid,
aname, 'IsIdentity') = 1 THEN '√' ELSE '' END AS 标识,
CASE WHEN EXISTS
(SELECT 1
FROM dbosysindexes si INNER JOIN
dbosysindexkeys sik ON siid = sikid AND siindid = sikindid INNER JOIN
dbosyscolumns sc ON scid = sikid AND sccolid = sikcolid INNER JOIN
dbosysobjects so ON soname = siname AND soxtype = 'PK'
WHERE scid = aid AND sccolid = acolid) THEN '√' ELSE '' END AS 主键,
bname AS 类型, alength AS 长度, COLUMNPROPERTY(aid, aname, 'PRECISION')
AS 精度, ISNULL(COLUMNPROPERTY(aid, aname, 'Scale'), 0) AS 小数位数,
CASE WHEN aisnullable = 1 THEN '√' ELSE '' END AS 允许空, ISNULL(etext, '')
AS 默认值, ISNULL(g[value], '') AS 字段说明, dcrdate AS 创建时间,
CASE WHEN acolorder = 1 THEN drefdate ELSE NULL END AS 更改时间
FROM dbosyscolumns a LEFT OUTER JOIN
dbosystypes b ON axtype = bxusertype INNER JOIN
dbosysobjects d ON aid = did AND dxtype = 'U' AND
dstatus >= 0 LEFT OUTER JOIN
dbosyscomments e ON acdefault = eid LEFT OUTER JOIN
dbosysproperties g ON aid = gid AND acolid = gsmallid AND
gname = 'MS_Description' LEFT OUTER JOIN
dbosysproperties f ON did = f
id AND fsmallid = 0 AND
fname = 'MS_Description'
ORDER BY dname, acolorder
如果要查整张表的所有字段的话 : select from table(table为你要查询的表名)
查询表中的某些字段(如id 和 name) : select id,name from table
使用sqlserver
查询语句就能够看见表中的字段名了;
1、查看所有字段语法:select
from
表名。这里的号表示的所有字段;如图所示
2、直接修改表也可以看见所有表中的字段名,选中所要查看字段的数据表“右键”-“修改”。
用Sql语句查询指定表格中指定字段的数据类型
一、语句通过systypes,syscolumns,sysobjects,三个系统表格联合检索获取结果。
systypes:数据库支持的数据类型属性。
syscolumns:数据库中各表格结构属性。
sysobjects:数据库中所有对象的属性。
二、检索语句演示
1、示例表格:base_zwb
2、语句如下:
select name from systypes wherextype in (select xtype from syscolumns where name = 'zw_mc' and
id in (select ID from sysobjects where name = 'base_zwb'));
语句解析:
1):select ID from sysobjects where name = 'base_zwb'),从表格‘sysobjects ’中,获取表格'base_zwb'的对象ID
2):select xtype from syscolumns where name = 'zw_mc' and id in (select ID from sysobjects where name = 'base_zwb'),以字段名称‘zw_mc’和第1步中获取的‘ID’,从表格‘syscolumns ’中获取数据类型的编号'xtype'
3):以第2部获取的 'xtype'编号,从表格‘systypes ’中获取数据类型。
结果如图:
select from 表名 where ‘列名1’=‘值’,'列名2'='值'
例如从一个学生成绩表(course)中查找语文不及格的学生
select from course
where ‘语文’<60
这次查询表中的字段名的目标是在写程序的时候需要写一点sql语句,但是表的字段太多了,如果一个一个去复制的话太慢了,而且有可能会复制漏了某个字段,所以利用自己数据库的知识,写了个sql语句直接生成字段名字符串,例如下面我要写一个select语句,需要生成表所有的字段:
declare @s varchar(1000)
select @s = isnull(@s+',', '') + [name] from syscolumns where id = object_id('相应表名')
select @s
获取字段名已经字段类型,类型长度
SELECT acolid as ID,aname as ColumnName,bname as DataType,alength
as Length FROM syscolumns a,systypes b WHERE aid=
object_id('相应的表名') and axtype=bxtype
and bname <> 'sysname' order by acolid
以上就是关于sql如何获得某个数据库里面的表的字段名,字段类型,字段长度(sql server2005)全部的内容,包括:sql如何获得某个数据库里面的表的字段名,字段类型,字段长度(sql server2005)、SQL获取表,字段,类型的代码、sql如何查表中字段的数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)