英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论