比较两个表的定义。

huangapple go评论49阅读模式
英文:

Compare the Definitions of Two Tables

问题

在T-SQL中,有办法以编程方式比较两个表的定义。

不仅包括列名和数据类型,还包括以下由以下命令返回的所有定义:

sp_help 'table_name'

英文:

Is there a way to compare programmatically in T-SQL the definitions of two tables.

Not only the column names and the data types, but all definitions that are returned by:

sp_help 'table_name'

答案1

得分: 2

我建议的最佳实践是安装Visual Studio,创建一个数据库项目,将源数据库导入其中,然后将目标数据库与数据库项目进行比较。(全部在Visual Studio中进行)

然后,如果需要的话,您也可以将数据库项目放入源代码控制中。

它使用了Sql Server模式比较。仅使用模式比较也可以是一种解决方案。

英文:

I would say best practice is to install Visual Studio, make a database project, import a source database into it, and then compare target databases to the database project. (All in Visual Studio)

Then you can also put the database project in source control if you want.

It uses the Sql Server Schema compare. Using that alone could also be a solution.

答案2

得分: 1

以下示例可能是您问题的一部分解决方案。它返回在结果中显示的任何属性上两个表之间存在不匹配的行。正如其他人提到的,有专门的工具可用于以更复杂的方式比较数据库对象。

SELECT * FROM sys.dm_exec_describe_first_result_set ('SELECT * FROM tbl1',NULL,NULL)
EXCEPT
SELECT * FROM sys.dm_exec_describe_first_result_set ('SELECT * FROM tbl2',NULL,NULL);
英文:

The following example may be part of the solution for you. It returns any rows where there is a mismatch between the two tables on any of the attributes shown in the result. As others have mentioned, there are specialist tools used to compare database objects in a much more sophisticated way.

SELECT * FROM sys.dm_exec_describe_first_result_set ('SELECT * FROM tbl1',NULL,NULL)
EXCEPT
SELECT * FROM sys.dm_exec_describe_first_result_set ('SELECT * FROM tbl2',NULL,NULL);

huangapple
  • 本文由 发表于 2023年5月29日 20:35:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定