获取Oracle、SqlServer表名、主键值、属性名
更新时间:2023-08-17 09:07:01 阅读量: 资格考试认证 文档下载
//获取表名,列名
SELECT TOP 100 PERCENT AS e_table_name, AS e_column_name,
AS e_column_type
FROM dbo.sysobjects INNER JOIN
dbo.syscolumns ON dbo.sysobjects.id = dbo.syscolumns.id INNER JOIN
dbo.systypes ON dbo.syscolumns.xtype = dbo.systypes.xtype
where = 'info_bridge'
ORDER BY
/**
*获取主键
*/
select COLUMN_NAME = convert(sysname,)
from
sysindexes i, syscolumns c, sysobjects o
where o.id = object_id('[YourTableName]')
and o.id = c.id
and o.id = i.id
and (i.status & 0x800) = 0x800
and ( = index_col ('[YourTableName]', i.indid, 1) or
= index_col ('[YourTableName]', i.indid, 2) or
= index_col ('[YourTableName]', i.indid, 3) or
= index_col ('[YourTableName]', i.indid, 4) or
= index_col ('[YourTableName]', i.indid, 5) or
= index_col ('[YourTableName]', i.indid, 6) or
= index_col ('[YourTableName]', i.indid, 7) or
= index_col ('[YourTableName]', i.indid, 8) or
= index_col ('[YourTableName]', i.indid, 9) or
= index_col ('[YourTableName]', i.indid, 10) or
= index_col ('[YourTableName]', i.indid, 11) or
= index_col ('[YourTableName]', i.indid, 12) or
= index_col ('[YourTableName]', i.indid, 13) or
= index_col ('[YourTableName]', i.indid, 14) or
= index_col ('[YourTableName]', i.indid, 15) or
= index_col ('[YourTableName]', i.indid, 16)
)
declare @table_name as varchar(max)
set @table_name = '你的表名'
select , , sys.columns.max_length, sys.columns.is_nullable,
(select count(*) from sys.identity_columns where sys.identity_columns.object_id = sys.columns.object_id and sys.columns.column_id = sys.identity_columns.column_id) as is_identity ,
(select value from sys.extended_properties where sys.extended_properties.major_id = sys.columns.object_id and sys.extended_properties.minor_id = sys.columns.column_id) as description
from sys.columns, sys.tables, sys.types where sys.columns.object_id = sys.tables.object_id and sys.columns.system_type_id=sys.types.system_type_id and http://doc.guand
ang.net=@table_name order by sys.columns.column_id
一、oracle
1、获取当前oracle数据库中的所有表
select table_name from user_tables
2、查询某
个表中的字段名称、类型、精度、长度、是否为空
select COLUMN_NAME,DATA_TYPE,DATA_PRECISION,DATA_SCALE,NULLABLE
from user_tab_columns
where table_name ='YourTableName'
3、查询某个表中的主键字段名
select col.column_name
from user_constraints con, user_cons_columns col
where con.constraint_name = col.constraint_name
and con.constraint_type='P'
and col.table_name = 'YourTableName'
4、查询某个表中的外键字段名称、所引用表名、所应用字段名
select distinct(col.column_name),r.table_name,r.column_name
from
user_constraints con,
user_cons_columns col,
(select t2.table_name,t2.column_name,t1.r_constraint_name
from user_constraints t1,user_cons_columns t2
where t1.r_constraint_name=t2.constraint_name
and t1.table_name='YourTableName'
) r
where con.constraint_name=col.constraint_name
and con.r_constraint_name=r.r_constraint_name
and con.table_name='YourTableName'
5、如何从Oracle中取得表的注释
user_tab_comments;表注释
user_col_comments;表字段注释
以上两个只能获取自己用户的表的注释信息,如果要访问自己
能够访问的其他用户的表,则需要使用:
all_tab_comments;表注释
all_col_comments;表字段注释
当然,如果有DBA权限,则可以使用
dba_tab_comments;表注释
dba_col_comments;表字段注释
dba*和all*最好指定owner条件。user*没有该字段
user_tab_comments;表注释
user_col_comments;表字段注释
二、SQLServer
1、读取库中的所有表名
select name from sysobjects where xtype='u'
2、字段
SELECT ,,c.xprec,c.xscale,c.isnullable
FROM systypes t,syscolumns c
WHERE t.xtype=c.xtype
AND c.id = (SELECT id FROM sysobjects WHERE name='YourTableName')
ORDER BY c.colid
3、主键(参考SqlServer系统存储过程sp_pkeys)
select COLUMN_NAME = convert(sysname,)
from
sysindexes i, syscolumns c, sysobjects o
where o.id = object_id('[YourTableName]')
and o.id = c.id
and o.id = i.id
and (i.status & 0x800) = 0x800
and ( = index_col ('[YourTableName]', i.indid, 1) or
= index_col ('[YourTableName]', i.indid, 2) or
= index_col ('[YourTableName]', i.indid, 3) or
http://doc.guandang.
net = index_col ('[YourTableName]', i.indid, 4) or
= index_col ('[YourTableName]', i.indid, 5) or
= index_col ('[YourTableName]', i.indid, 6) or
= index_col ('[YourTableName]', i.indid, 7) or
= index_col ('[YourTableName]', i.indid, 8) or
= index_col ('[YourTableName]', i.indid, 9) or
= index_col ('[YourTableName]', i.indid, 10) or
= index_col ('[YourTableName]', i.indid, 11) or
= index_col ('[YourTableName]', i.indid, 12) or
= index_col ('[YourTableName]', i.indid, 13) or
= index_col ('[YourTableName]', i.indid, 14) or
= index_col ('[YourTableName]', i.indid, 15) or
= index_col ('[YourTableName]', i.indid, 16)
)
BND-6DD3B1A0933
select name from sysindexes where id = object_id( 'info_bridge') and status = 2066
4、外键
select ,t2.rtableName,
from
(select , f.constid as temp
from syscolumns col,sysforeignkeys f
where f.fkeyid=col.id
and f.fkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t1 ,
(select OBJECT_NAME(f.rkeyid) as rtableName,, f.constid as temp
from syscolumns col,sysforeignkeys f
where f.rkeyid=col.id
and f.rkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t2
where t1.temp=t2.temp 三、Access
1、所有表清单
conn.Open();
dt= conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
2、表
结构
conn.Open();
dtColumnsInfo = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, strTableName,null });
正在阅读:
获取Oracle、SqlServer表名、主键值、属性名08-17
E算量使用教程 - 图文10-31
表彰通报范文02-13
仓库管理制度流程与操作规范03-12
二月初二02-06
Tecplot 常用数据格式(转)06-08
信号分析与处理_杨西侠_课后答案二三五章03-08
飞歌简介(2) - 图文11-07
- 梳理《史记》素材,为作文添彩
- 2012呼和浩特驾照模拟考试B2车型试题
- 关于全面推进施工现场标准化管理实施的通知(红头文件)
- 江西省房屋建筑和市政基础设施工程施工招标文件范本
- 律师与公证制度第2阶段练习题
- 2019-2020年最新人教版PEP初三英语九年级上册精编单元练习unit6训练测试卷内含听力文件及听力原文
- 小升初数学模拟试卷(十四) 北京版 Word版,含答案
- 认识创新思维特点 探讨创新教育方法-精选教育文档
- 00266 自考 社会心理学一(复习题大全)
- 多媒体在语文教学中的运用效果
- 派出所派出所教导员述职报告
- 低压电工作业考试B
- 18秋福建师范大学《管理心理学》在线作业一4
- 中国铝业公司职工违规违纪处分暂行规定
- 13建筑力学复习题(答案)
- 2008年新密市师德征文获奖名单 - 图文
- 保安员培训考试题库(附答案)
- 银川市贺兰一中一模试卷
- 2011—2017年新课标全国卷2文科数学试题分类汇编 - 1.集合
- 湖北省襄阳市第五中学届高三生物五月模拟考试试题一
- SqlServer
- 属性
- 获取
- Oracle
- wouldrather的用法
- 黄湾中心小学课堂教学常规问卷调查反馈
- 第11章计算机系统的维护及优化
- 春江花月夜之感想
- 论奥斯卡王尔德《道林格雷的画像》中的死亡结局与唯美主义
- 人类与环境之间的关系探讨
- 语文高级教师职称申报述职报告
- MTT法观察细胞生长曲线
- c语言 第4讲选择结构程序设计
- 诚信教育主题班会教案
- 工程热力学思考题答案,第八章
- 历史试题普班
- 基于GPS和陀螺仪的水稻插秧机自动导航设计
- 我国甲状腺癌外科治疗现状
- 与明星裸婚的日子分集剧情第3集(共6集)_剧情介绍_大结局_演员表
- 环境保护概论复习题
- 苏州园林考察报告
- 2016年北京中考物理试题(图片版,有答案)
- 近20年我国饮用水污染事故分析及防治对策
- 学习教育工作会议精神心得体会