谁能推荐一个sqlserver数据库比较工具

Akon2008 2011-02-24 12:50:21
谁能推荐一个sqlserver数据库比较工具,比较两个数据库之间的差异
表,字段;
存储过程
视图
函数

最主要还是表

先谢谢了
...全文
1690 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

仅针对SQL Server 2005
可对比对象:
1. 表
a) 字段,数据类型,字段长度、主键、默认值、是否为空
2. 2 .视图
3. 3.存储过程
4. 4.函数
5. 5.触发器
详细信息

BXC-SQLServer数据库对象对比工具 1.3.100105
sqlserver数据库对比工具 1.0
试用了前两个,第二个功能比较强,支持不同版本数据库……
[/Quote]

试用了前两个?是
BXC-SQLServer数据库对象对比工具 1.3.100105
sqlserver数据库对比工具 1.0
可是上面两个链接到的是同一个页面,BXC比较的不是特别准确啊
秀逗 2012-06-05
  • 打赏
  • 举报
回复
回复第11楼,支持第二个,第一个太慢了。
昵称被占用了 2011-03-16
  • 打赏
  • 举报
回复
自己写个应该用不了多少时间
HiddenBlade 2011-03-16
  • 打赏
  • 举报
回复
sql delta
4.x 可以找到破解,支持到sql2005
5.x 14天试用,可以支持sql2008
lds1ove 2011-03-03
  • 打赏
  • 举报
回复
tablediff
Akon2008 2011-03-03
  • 打赏
  • 举报
回复
回:hokor,呵呵,我现在用的就是这个,但这个有些缺点,比如,两边数据库表和过程对比的内容一旦多了,就非常的慢,另外他也没有提供,按选择对象进行比较,我理想中就是我选择表对象,就可以将两个库之间表对比出来
hokor 2011-02-28
  • 打赏
  • 举报
回复
仅针对SQL Server 2005
可对比对象:
1. 表
a) 字段,数据类型,字段长度、主键、默认值、是否为空
2. 2 .视图
3. 3.存储过程
4. 4.函数
5. 5.触发器
详细信息

BXC-SQLServer数据库对象对比工具 1.3.100105
sqlserver数据库对比工具 1.0
试用了前两个,第二个功能比较强,支持不同版本数据库比较。
唵嘛呢叭咪吽 2011-02-24
  • 打赏
  • 举报
回复
自己写咯
快溜 2011-02-24
  • 打赏
  • 举报
回复
PowerDesigner
fwacky 2011-02-24
  • 打赏
  • 举报
回复

可能是没写清楚,我要的是两个数据库之间的,并不是某一张表或视图,是两个库,比如,我将两个数据库连接字符告诉程序,程序就能告诉我,这两个库之间有什么差别,从表,视图,等对象来比较
=========================
这还有写sql吗?
你直接把两个 数据的表和视图,存储过程都查出来。
在页面上显示,不对全看了。还用比较吗?
快溜 2011-02-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 akon2008 的回复:]
可能是没写清楚,我要的是两个数据库之间的,并不是某一张表或视图,是两个库,比如,我将两个数据库连接字符告诉程序,程序就能告诉我,这两个库之间有什么差别,从表,视图,等对象来比较
[/Quote]
看一楼,找人教你怎么用。
Akon2008 2011-02-24
  • 打赏
  • 举报
回复
可能是没写清楚,我要的是两个数据库之间的,并不是某一张表或视图,是两个库,比如,我将两个数据库连接字符告诉程序,程序就能告诉我,这两个库之间有什么差别,从表,视图,等对象来比较
jwwyqs 2011-02-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 masschoi 的回复:]
存储过程要写在数据库里
个人认为在程序里处理比较好
[/Quote]
哎那就直接在程序里面调用输出结果就是了,程序里面写那也要访问数据库的啊
唵嘛呢叭咪吽 2011-02-24
  • 打赏
  • 举报
回复
存储过程要写在数据库里
个人认为在程序里处理比较好
jwwyqs 2011-02-24
  • 打赏
  • 举报
回复
-- =============================================
-- Author:大乌龟的
-- Description: <比较两个数据库的表结构差异并自动生成修改和插入表字段脚本>
--exec p_comparestructure 'ZhongYDBDevelop','ZhongYDBIssued'
-- =============================================
ALTER proc [dbo].[p_comparestructure]
@dbname1 varchar(250),--要比较的数据库名1
@dbname2 varchar(250)--要比较的数据库名2
as
set @dbname1='['+@dbname1+']'
set @dbname2='['+@dbname2+']'

create table #tb1(表名1 varchar(250),字段名 varchar(250),序号 int,标识 bit,主键 bit,类型 varchar(250),
占用字节数 int,长度 int,小数位数 int,允许空 bit,默认值 sql_variant,字段说明 sql_variant)

create table #tb2(表名2 varchar(250),字段名 varchar(250),序号 int,标识 bit,主键 bit,类型 varchar(250),
占用字节数 int,长度 int,小数位数 int,允许空 bit,默认值 sql_variant,字段说明 sql_variant)

--得到数据库1的结构
exec('insert into #tb1 SELECT
表名=d.name,字段名=a.name,序号=a.colid,
标识=case when a.status=0x80 then 1 else 0 end,
主键=case when exists(SELECT 1 FROM '+@dbname1+'.dbo.sysobjects where xtype=''PK'' and parent_obj=a.id and name in (
SELECT name FROM '+@dbname1+'.dbo.sysindexes WHERE indid in(
SELECT indid FROM '+@dbname1+'.dbo.sysindexkeys WHERE id = a.id AND colid=a.colid
))) then 1 else 0 end,
类型=b.name,占用字节数=a.length,长度=a.prec,小数位数=a.scale,允许空=a.isnullable,
默认值=isnull(e.text,''''),字段说明=isnull(g.[value],'''')
FROM '+@dbname1+'.dbo.syscolumns a
left join '+@dbname1+'.dbo.systypes b on a.xtype=b.xusertype
inner join '+@dbname1+'.dbo.sysobjects d on a.id=d.id and d.xtype=''U'' and d.name<>''dtproperties''
left join '+@dbname1+'.dbo.syscomments e on a.cdefault=e.id
left join '+@dbname1+'.sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id
order by a.id,a.colorder')
--select * from csdntest.sys.extended_properties
--得到数据库2的结构
exec('insert into #tb2 SELECT
表名=d.name,字段名=a.name,序号=a.colid,
标识=case when a.status=0x80 then 1 else 0 end,
主键=case when exists(SELECT 1 FROM '+@dbname2+'.dbo.sysobjects where xtype=''PK'' and parent_obj=a.id and name in (
SELECT name FROM '+@dbname2+'.dbo.sysindexes WHERE indid in(
SELECT indid FROM '+@dbname2+'.dbo.sysindexkeys WHERE id = a.id AND colid=a.colid
))) then 1 else 0 end,
类型=b.name,占用字节数=a.length,长度=a.prec,小数位数=a.scale,允许空=a.isnullable,
默认值=isnull(e.text,''''),字段说明=isnull(g.[value],'''')
FROM '+@dbname2+'.dbo.syscolumns a
left join '+@dbname2+'.dbo.systypes b on a.xtype=b.xusertype
inner join '+@dbname2+'.dbo.sysobjects d on a.id=d.id and d.xtype=''U'' and d.name<>''dtproperties''
left join '+@dbname2+'.dbo.syscomments e on a.cdefault=e.id
left join '+@dbname2+'.sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id
order by a.id,a.colorder')
--and not exists(select 1 from #tb2 where 表名2=a.表名1)
select 比较结果=case when a.表名1 is null and b.序号=1 then @dbname1+'——缺少表:'+b.表名2
when b.表名2 is null and a.序号=1 then @dbname2+'——缺少表:'+a.表名1
when a.字段名 is null and exists(select 1 from #tb1 where 表名1=b.表名2) then
'/*'+@dbname1+'——['+b.表名2+'] 缺少字段:'+b.字段名+'*/alter table '+b.表名2+' drop column '+b.字段名
when b.字段名 is null and exists(select 1 from #tb2 where 表名2=a.表名1) and a.类型='decimal' then
'/*'+@dbname2+'——['+a.表名1+'] 缺少字段:'+a.字段名+'*/ alter table '+a.表名1+' add '+a.字段名+' '
+a.类型+'('+ltrim(str(a.长度))+','+ltrim(str(isnull(a.小数位数,'')))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when b.字段名 is null and exists(select 1 from #tb2 where 表名2=a.表名1) and a.类型='nvarchar' then
'/*'+@dbname2+'——['+a.表名1+'] 缺少字段:'+a.字段名+'*/ alter table '+a.表名1+' add '+a.字段名+' '
+a.类型+'('+ltrim(str(a.长度))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when b.字段名 is null and exists(select 1 from #tb2 where 表名2=a.表名1) and a.类型 not in('nvarchar','decimal') then
'/*'+@dbname2+'——['+a.表名1+'] 缺少字段:'+a.字段名+'*/ alter table '+a.表名1+' add '+a.字段名+' '
+a.类型+(case when a.允许空=0 then ' not null' else ' null' end)
when a.标识<>b.标识 then '--标识不同'
when a.主键<>b.主键 then '--主键设置不同'
when a.类型<>b.类型 and a.类型='decimal' then
'/*字段类型不同*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+'('+ltrim(str(a.长度))+','+ltrim(str(isnull(a.小数位数,'')))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when a.类型<>b.类型 and a.类型='nvarchar' then
'/*字段类型不同*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+'('+ltrim(str(a.长度))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when a.类型<>b.类型 and a.类型 not in('nvarchar','decimal') then
'/*字段类型不同*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+(case when a.允许空=0 then ' not null' else ' null' end)
when a.占用字节数<>b.占用字节数 then
'/*占用字节数*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+'('+ltrim(str(a.长度))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when a.长度<>b.长度 then
'/*长度不同*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+'('+ltrim(str(a.长度))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when a.小数位数<>b.小数位数 then
'--小数位数不同*/ alter table '+a.表名1+' alter column '+a.字段名+' '+a.类型+'('+ltrim(str(a.长度))+','+ltrim(str(isnull(a.小数位数,'')))+')'+(case when a.允许空=0 then ' not null' else ' null' end)
when a.允许空<>b.允许空 then '--是否允许空不同'
when a.默认值<>b.默认值 then
'/*默认值不同*/ alter table '+a.表名1+' add default(0) for '+a.字段名+' with values'
--when isnull(a.字段说明,'')<>'' and isnull(b.字段说明,'')='' then
--'EXEC sys.sp_addextendedproperty @name=N'''+'MS_Description'+''', @value=N'''+a.字段说明--+''' , @level0type=N'''+'SCHEMA'+''',@level0name=N'''+'dbo'+''', @level1type=N'''+'TABLE'+''',@level1name=N'''+b.表名2+''', @level2type=N'''+'COLUMN'+''',@level2name=N'''+b.字段名+'''--字段说明不同'
else '' end,
*
from #tb1 a
full join #tb2 b on a.表名1=b.表名2 and a.字段名=b.字段名
where a.表名1 is null or a.字段名 is null or b.表名2 is null or b.字段名 is null
or a.标识<>b.标识 or a.主键<>b.主键 or a.类型<>b.类型
or a.占用字节数<>b.占用字节数 or a.长度<>b.长度 or a.小数位数<>b.小数位数
or a.允许空<>b.允许空 or a.默认值<>b.默认值-- or a.字段说明<>b.字段说明
order by isnull(a.表名1,b.表名2),isnull(a.序号,b.序号),isnull(a.字段名,b.字段名)
feilniu 2011-02-24
  • 打赏
  • 举报
回复
好像RedGate系列产品有数据库对比工具。

最简单又省钱的方式是:
把数据库对象导出为文本,然后进行文本比较。

这样,一款开源的WinMerge文本对比工具就搞定了。
jwwyqs 2011-02-24
  • 打赏
  • 举报
回复
写一个存储过程来处理

11,849

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧