with nms130tables as (select * from dblink('host=127.0.0.1 dbname=nms_130 user=postgres password=hik12345+','select schemaname, tablename from pg_tables') as t(schemaname varchar,tablename varchar)),
nms130columns as (select * from dblink('host=127.0.0.1 dbname=nms_130 user=postgres password=hik12345+','select table_catalog, table_schema, table_name, column_name, data_type, ordinal_position from information_schema.columns
') as t(table_catalog varchar,table_schema varchar,table_name varchar, column_name varchar, data_type varchar, ordinal_position int)
where table_catalog = 'nms_130' and table_schema = 'public'
) --修改,110有,130也有,表名一致、欄位名稱一致、字段型別不一致(字段長度暫時不考慮)
select cl.table_catalog,
cl.table_name,
cl.column_name,
cl.data_type
from nms130columns cl
where 1 = 1
and exists (select 1 from information_schema.columns tab where table_catalog = 'nms_120' and table_schema = 'public' and tab.table_name = cl.table_name and tab.column_name = cl.column_name and tab.data_type <> cl.data_type)
order by cl.table_name, cl.ordinal_position
-- 新增、110沒有,130有的表名一致、欄位名一致、段型別一致
/*select cl.table_catalog,
cl.table_name,
cl.column_name,
cl.data_type
from nms130columns cl
where 1 = 1
and not exists (select 1 from information_schema.columns tab where table_catalog = 'nms_120' and table_schema = 'public' and tab.table_name = cl.table_name and tab.column_name = cl.column_name)
order by cl.table_name, cl.ordinal_position*/
-- 刪除、110有、120沒有的表名一致、欄位名一致的型別
/*select cl.table_catalog,
cl.table_name,
cl.column_name,
cl.data_type
from information_schema.columns cl
where cl.table_catalog = 'nms_130' and cl.table_schema = 'public'
and not exists (select 1 from nms130columns tab where tab.table_name = cl.table_name and tab.column_name = cl.column_name)
order by cl.table_name, cl.ordinal_position*/
資料庫公升級指令碼
工作流資料庫指令碼公升級技術小結 1.修改字段長度或型別 只能加大,不能減小 修改型別時得注意資料的可轉化性 mysql alter table 表名 modify column 欄位名 字段型別定義 oracle,修改型別時所改字段的資料必須為空 alter table 表名 modify 欄位名...
資料庫公升級
公升級 的版本時,我們有時候希望可以把原資料庫中的資料也保留下來,那麼這個時候我們就需要用到資料庫的公升級。在 android 中sqliteopenhelper 中定義了 onupgrade sqlitedatabase db,int oldversion,int newversion 函式來進行...
資料庫語法對比
title toclayout categories br 資料庫語法對比 true blog blog blog 2019 10 11 04 24 43 0700 統計了在開發過程中,不同資料庫實現相同功能的不同語句。在開發過程中,需要寫一些不同資料庫間的相同功能sql。今天有時間就特地總結一下,...