1. 程式人生 > >資料庫表結構比較SQL

資料庫表結構比較SQL

--查詢A資料庫存在,B資料庫不存在的表
select * from user_tables t
where not exists(select 1 from [email protected] t1 where t.TABLE_NAME=t1.TABLE_NAME)
order by last_analyzed desc;
--查詢A資料庫與B資料庫表列不一致的表
select DISTINCT table_name from ALL_TAB_COLUMNS t
where not exists(select 1 from [email protected] t1 where t.TABLE_NAME=t1.TABLE_NAME and t.COLUMN_NAME=t1.COLUMN_NAME)
and owner='COSEM'
order by table_name
--查詢A資料庫與B資料庫表列不一致的列
select table_name,COLUMN_NAME from ALL_TAB_COLUMNS t
where not exists(select 1 from

[email protected] t1 where t.TABLE_NAME=t1.TABLE_NAME and t.COLUMN_NAME=t1.COLUMN_NAME)
and owner='COSEM'
and table_name='SH_INV_DESC'
order by table_name,COLUMN_NAME