手机版

获取Oracle、SqlServer表名、主键值、属性名

发布时间:2021-06-06   来源:未知    
字号:

//获取表名,列名
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、查询某

获取Oracle、SqlServer表名、主键值、属性名.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)