简体   繁体   English

SQL Server-使用C#将“创建表” SQL脚本与表定义进行比较

[英]SQL Server - Compare a 'CREATE TABLE' SQL script to a table definition using c#

I'm trying to compare the script in a .sql file against a tables schema definition on a SQL Server database using C#. 我正在尝试使用C#将.sql文件中的脚本与SQL Server数据库上的表架构定义进行比较。 I also want to generate an alter table script based on the outcome of this comparison. 我还想基于此比较的结果生成一个alter table脚本。

This can be done using Visual Studios 'Schema Compare' tool where a script gets generated afterwards. 可以使用Visual Studios的“架构比较”工具完成此任务,此后将生成脚本。 However it doesn't look like there is an API available for this? 但是,看起来没有可用的API吗?

So far I've tried using ScriptDom to read the .sql file but I cannot alter the script or compare this with the target table. 到目前为止,我已经尝试使用ScriptDom读取.sql文件,但是我无法更改脚本或将其与目标表进行比较。

Any ideas what I could do here or any other languages that I could utilise? 有什么想法可以在这里做什么或可以使用的其他任何语言?

Why don't you just execute the script in a test database in order to create the table and then use a third party API like xSQL Schema Compare SDK to compare the two tables. 您为什么不只是在测试数据库中执行脚本以创建表,然后使用xSQL Schema Compare SDK之类的第三方API比较两个表。 xSQL Schema Compare will also generate the scripts to synchronize the two tables if it finds any differences. 如果发现任何差异,xSQL Schema Compare还将生成用于同步两个表的脚本。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM