-- 比較兩個資料庫中表的差異
-- u表,p儲存過程,v檢視
-- intfsimsnew新庫,intfsims舊庫
select ntable = a.name, otable = b.name
from intfsimsnew..sysobjects a
left join intfsims..sysobjects b
on a.name = b.name
where isnull(b.name, '') = ''
and a.xtype = 'u'
union all
select ntable = b.name, otable = a.name
from intfsims..sysobjects a
left join intfsimsnew..sysobjects b
on a.name = b.name
where isnull(b.name, '') = ''
and a.xtype = 'u'
order by 1, 2
-- 比較兩個資料庫中每個表字段的差異
select
表名a = case when isnull(a.tablename, '') <> '' then a.tablename else b.tablename end,
欄位名a = a.fieldname,
欄位名b = b.fieldname,
順序= a.fieldsno,
說明= case when a.fieldtype <> b.fieldtype then '型別: ' + a.fieldtype + '-->' + b.fieldtype
when a.fieldsno <> b.fieldsno then '順序: ' + str(a.fieldsno) + '-->' + str(b.fieldsno)
when a.length <> b.length then '長度: ' + str(a.length) + '-->' + str(b.length)
when a.lensec <> b.lensec then '小數字: ' + str(a.lensec) + '-->' + str(b.lensec)
when a.allownull <> b.allownull then '允許空值: ' + str(a.allownull) + '-->' + str(b.allownull)
endfrom (select
tablename = b.name,
fieldname = a.name,
fieldsno = a.colid,
fieldtype = c.name,
length = a.length,
lensec = a.xscale,
allownull = a.isnullable
from intfsimsnew..syscolumns a
left join intfsimsnew..sysobjects b
on a.id = b.id
left join intfsimsnew..systypes c
on a.xusertype = c.xusertype
where b.xtype = 'u') a
full join (select
tablename = b.name,
fieldname = a.name,
fieldsno = a.colid,
fieldtype = c.name,
length = a.length,
lensec = a.xscale,
allownull = a.isnullable
from intfsims..syscolumns a
left join intfsims..sysobjects b
on a.id = b.id
left join intfsims..systypes c
on a.xusertype = c.xusertype
where b.xtype = 'u') b
on a.tablename = b.tablename
and a.fieldname = b.fieldname
where isnull(a.tablename, '') = ''
or isnull(b.tablename, '') = ''
or a.fieldtype <> b.fieldtype
or a.fieldsno <> b.fieldsno
or a.length <> b.length
or a.lensec <> b.lensec
or a.allownull <> b.allownull
order by 1, 4
兩個資料庫連線
可以建dblink 然後寫procedure 然後建 scheduler 定期同步或者在表的trigger裡面寫 怎麼寫procedure,建 scheduler 定期同步?還有就是dblink可不可以處理大資料量的資料 百萬條資料 一 db link的連線方式 1 已經配置本地服務 create ...
同步兩個資料庫
同步兩個資料庫的示例 有資料 srv1.庫名.author有欄位 id,name,phone,srv2.庫名.author有欄位 id,name,telphone,adress 要求 srv1.庫名.author增加記錄則srv1.庫名.author記錄增加 srv1.庫名.author的phone...
比較兩個資料庫的表結構差異
比較兩個資料庫的表結構差異 鄒建 2003.9 引用請保留此資訊 呼叫示例 exec p comparestructure xzkh model xzkh new if exists select from dbo.sysobjects where id object id n dbo p comp...