如何通过sql语句比较2个表结构
答案:2 悬赏:40 手机版
解决时间 2021-02-23 15:38
- 提问者网友:沦陷
- 2021-02-22 16:22
如何通过sql语句比较2个表结构
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-02-22 17:17
如果是Oracle数据库的话,可以按以下语句比较
select v1.table_name,v2.table_name, v1.column_name,v2.column_name,
v1.data_type,v2.data_type,v1.data_length,v2.data_length ,v1.data_precision,v2.data_precision,v1.data_scale,v2.data_scale
from
(select * from user_tab_columns where table_name='表1') v1 full join
(select * from user_tab_columns where table_name='表2') v2 on v1.column_name=v2.column_name
select v1.table_name,v2.table_name, v1.column_name,v2.column_name,
v1.data_type,v2.data_type,v1.data_length,v2.data_length ,v1.data_precision,v2.data_precision,v1.data_scale,v2.data_scale
from
(select * from user_tab_columns where table_name='表1') v1 full join
(select * from user_tab_columns where table_name='表2') v2 on v1.column_name=v2.column_name
全部回答
- 1楼网友:大漠
- 2021-02-22 18:57
如果是sql server 2005以上的,可以用except运算
select * from a
except
select * from b
union
(select * from b
except
select * from a
)
通用的
select * from a where not exists(select * from b where b.pid=a.pid and b.name=a.name)
union
select * from b where not exists(select * from a where b.pid=a.pid and b.name=a.name)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯