分析:由于表结构中字段比较多,手工比较很浪费时间,而且不能保证不出错误对于表中的数据那就能多了,更不能靠这种方式比较
为了思考问题简单和方便测试,首先先建立两个测试表,并插入一些测试数据吧,sql如下:
>看表名字
SELECT
table_name
FROM
all_tables
看字段
SELECT
column_name
FROM
all_tab_columns
WHERE
table_name
=
'表名字';
如果是
SQLPLUS
客户端的话,就直接
DESC
表名字,就能看表结构了。
显示Oracle数据库表中的列有以下两种方式。
1、在命令窗口下输入desc 表名。
如:
desc test;2、通过sql语句查询,语句如下:
注意:表名必须大写。
go
--2005实现数据库表字段属性统计(2000里的系统表sysproperties描述表不存在,2005里用sysextended_properties视图替代)
select
[表名]=cName,
[表说明]=isnull(f[value],''),
[列名]=aName,
[列序号]=aColumn_id,
[标识]=case when is_identity=1 then '√' else '' end,
[主键]=case when exists(select 1 from sysobjects x join sysindexes y on xType=N'PK' and xName=yName
join sysindexkeys z on zID=aObject_id and zindid=yindex_id and zColid=aColumn_id)
then '√' else '' end,
[类型]=bName,
[字节数]=case when a[max_length]=-1 and bName!='xml' then 'max/2G'
when bName='xml' then '2^31-1字节/2G'
else rtrim(a[max_length]) end,
[长度]=case when ColumnProperty(aobject_id,aName,'Precision')=-1 then '2^31-1'
else rtrim(ColumnProperty(aobject_id,aName,'Precision')) end,
[小数]=isnull(ColumnProperty(aobject_id,aName,'Scale'),0),
[是否为空]=case when ais_nullable=1 then '√' else '' end,
[列说明]=isnull(e[value],''),
[默认值]=isnull(dtext,'')
from
syscolumns a
left join
systypes b on auser_type_id=buser_type_id
inner join
sysobjects c on aobject_id=cobject_id and cType='U'
left join
syscomments d on adefault_object_id=dID
left join
sysextended_properties e on emajor_id=cobject_id and eminor_id=aColumn_id and eclass=1
left join
sysextended_properties f on fmajor_id=cobject_id and fminor_id=0 and fclass=1select aowner 所属用户,atable_name 表名,acolumn_name 字段名,adata_type 字段类型,a字段长度,a字段精度,a是否为空,a创建日期,a最后修改日期,
case when aowner=downer and atable_name=dtable_name and acolumn_name=dcolumn_name then '主键' else '' end 是否主键
from
(select aowner,atable_name,bcolumn_name,bdata_type,case when bdata_precision is null then bdata_length else data_precision end 字段长度,
data_scale 字段精度,
decode(nullable,'Y','√','N','×') 是否为空,ccreated 创建日期,clast_ddl_time 最后修改日期
from all_tables a,all_tab_columns b,all_objects c
where atable_name=btable_name and aowner=bowner
and aowner=cowner
and atable_name=cobject_name
and aowner='SCOTT'--此处用户名可以更改,但必须大写英文,也可以把这行删除
and cobject_type='TABLE') a
left join
(select aowner,atable_name,acolumn_name,aconstraint_name from user_cons_columns a, user_constraints b
where aconstraint_name = bconstraint_name and bconstraint_type = 'P') d
on aowner=downer and atable_name=dtable_name and acolumn_name=dcolumn_name
order by aowner,atable_name;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)