我在开发软件过程中会不段的添加新的字段,并更新某些已存在的字段的数据类型.但是客户电脑上软件已经用了.如何对比我电脑上新的数据库更新客户电脑上的数据结构呢?例如:
表Custom.
我的电脑上有如下字段
CustomNO
CustomName
CustomPhone
Custom_Type
Custom_Flag
Custom_Address
但是客户机上只有
CustomNO
CustomName
CustomPhone
有什么样的好的办法进行更新数据库呢?
表Custom.
我的电脑上有如下字段
CustomNO
CustomName
CustomPhone
Custom_Type
Custom_Flag
Custom_Address
但是客户机上只有
CustomNO
CustomName
CustomPhone
有什么样的好的办法进行更新数据库呢?
--存在CustomNO的更新
update 客户机的表
set CustomName = n.CustomName,
CustomPhone = n.CustomPhone
from 客户机的表 m , 我的电脑上的表 n
where m.CustomNO = n.CustomNO
--不存在CustomNO 的插入
insert into 客户机的表(CustomNO ,CustomName ,CustomPhone ) select CustomNO ,CustomName ,CustomPhone from 我的电脑上的表 where CustomNO not in (select CustomNO from 客户机的表)
alter table 表名 add 列名 类型
数据库表的对比,通过系统表来做还是比较容易实现的,你可以搜索一下如何通过系统表来获取表信息(表的字段列表,字段类型、长度等)。然后根据对比差异生成Sql就可以了,不过要考虑的情况很多。网上也没有相关的工具,只能自己来做
alter table 表 add 字段 类型