文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SQL经验分享(二)取得数据库中所有的表名、字段名以及字段属于哪个表

SQL经验分享(二)取得数据库中所有的表名、字段名以及字段属于哪个表

时间:2011-05-29  来源:独孤伤

2.1取得数据库中所有表名

样例数据:


语句:

select t.name '表名' from sysobjects t where OBJECTPROPERTY(t.id, N'IsUserTable') = 1

或者用select name from sysobjects where type='U'

执行结果:



2.2 取得所有表中的所有字段名

语句:

select distinct c.name '字段名'  from sysobjects t, syscolumns c
where t.id = c.id   and  OBJECTPROPERTY(t.id, N'IsUserTable') = 1

执行结果:


注:字段较多,后面略

 

2.3查所有表和字段

语句:select t.name '表名' ,c.name '字段名'  from sysobjects t, syscolumns c
where t.id = c.id   and  OBJECTPROPERTY(t.id, N'IsUserTable') = 1  group by t.name,c.name

执行结果:


注:字段较多,后面略

 

2.4查某个表的所有字段

Table_1原始数据:


语句:
select t.name,c.name '字段名'  from sysobjects t, syscolumns c
where t.id = c.id   and  OBJECTPROPERTY(t.id, N'IsUserTable') = 1
and  t.name='Table_1'

执行结果:


 

2.5查字段属于哪个表(即找含有相同字段的表)

查询姓名列在哪些表中有

语句:

select distinct t.name from sysobjects t, syscolumns c
where t.id = c.id   and  OBJECTPROPERTY(t.id, N'IsUserTable') = 1
and c.name in ('姓名')

执行结果:


相关阅读 更多 +
排行榜 更多 +
吹风机射击 v1.0 安卓版

吹风机射击 v1.0 安卓版

飞行射击 下载
吹风机射击 v1.0 安卓版

吹风机射击 v1.0 安卓版

飞行射击 下载
吹风机射击 v1.0 安卓版

吹风机射击 v1.0 安卓版

飞行射击 下载