[英]SQL Comparing two Stored procedures between databases
I have two version of same database and need to campare some objects between them (stored procedures, views etc.) 我有相同数据库的两个版本,需要在它们之间添加一些对象(存储过程,视图等)。
Actually ?m using SQLDMO-SQLSMO to retrieve the Text of each object then I perform a text comparison. 实际上是使用SQLDMO-SQLSMO检索每个对象的文本,然后执行文本比较。 This is efective but take a long time most if I have more tan 1000+ objects.
这是有效的,但是如果我有更多棕褐色的1000多个对象,则最多会花费很长时间。
My question is. 我的问题是。 There is a simple way to perform this comparison ?
有一种简单的方法可以执行此比较吗? maybe an MD5 key generated on the databases ?
也许在数据库上生成了MD5密钥?
Why not just query for the definitions directly from SQL server instead of having the overhead of using the management objects? 为什么不直接从SQL Server直接查询定义,而又不使用管理对象呢?
SELECT
sysobjects.name AS [Object Name]
,(CASE sysobjects.xtype
WHEN 'P' THEN 'Stored Procedure'
WHEN 'TF' THEN 'Function'
WHEN 'TR' THEN 'Trigger'
WHEN 'V' THEN 'View' END) AS [Object Type]
,syscomments.text AS [Object Definition]
FROM
sysobjects
JOIN
syscomments
ON
sysobjects.id = syscomments.id
WHERE
sysobjects.xtype in ('P', 'TF', 'TR', 'V')
AND
sysobjects.category = 0
I ran that against a database I have here. 我是针对我这里的数据库运行的。 It returned ~1,500 definitions in 0.6 seconds.
它在0.6秒内返回了约1,500个定义。 If you run that against each server to collect all the definitions, you can do a comparison on object name, type, and definition in one big loop.
如果对每个服务器运行该命令以收集所有定义,则可以在一个大循环中对对象名称,类型和定义进行比较。
This will be an expensive operation memory-wise but should be pretty quick. 在内存方面,这将是一项昂贵的操作,但是应该很快。 Most of the CPU time will be spent doing the actual string comparisons.
大多数CPU时间将花费在进行实际的字符串比较上。
As for your other questions about a "key" available that you can compare, there's no such hash or equivalent that I know of. 至于您可以比较的有关“钥匙”的其他问题,我所知道的没有这样的哈希值或等效值。 In the
sys.syscomments
table you have the ctext
column (raw bytes of the SQL definition) and the text
column which is the text representation of those bytes. 在
sys.syscomments
表中,您具有ctext
列(SQL定义的原始字节)和text
列,它们是这些字节的文本表示形式。
FYI: If you have Visual Studio 2010 Premium or higher, there's a built-in Schema Compare tool that will do this all for you. 仅供参考:如果您具有Visual Studio 2010 Premium或更高版本,则有一个内置的Schema Compare工具可以为您完成所有这些工作。 There's also Open DBDiff or many others that are free.
还有Open DBDiff或许多其他免费的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.