简体   繁体   English

SQL Server DDL更改(列名,类型)

[英]SQL Server DDL changes (column names, types)

I need to audit DDL changes made to a database. 我需要审核对数据库所做的DDL更改。 Those changes need to be replicated in many other databases at a later time. 这些更改需要在以后的其他许多数据库中复制。 I found here that one can enable DDL triggers to keep track of DDL activities, and that works great for create table and drop table operations, because the trigger gets the T-SQL that was executed, and I can happily store it somewhere and simply execute it on the other servers later. 我在这里发现,可以启用DDL触发器来跟踪DDL活动,这对于create tabledrop table操作非常有用,因为该触发器获取已执行的T-SQL,并且我可以很高兴地将其存储在某个地方并简单地执行稍后在其他服务器上。

The problem I'm having is with alter operations: when a column name is changed from Management Studio, the event that is produced doesn't contain any information about columns! 我遇到的问题是alter操作:从Management Studio更改列名称时,产生的事件不包含有关列的任何信息! It just says the table was locked... What's more, if many columns are changed at once (say, column foo => oof , and also, column bar => rab ) the event is fired only once! 它只是说表已锁定...而且,如果一次更改许多列(例如,列foo => oof ,还有列bar => rab ),则仅触发一次事件!

My poor man's solution would be to have a table to store the structure of the table that's going to be altered, before and after the alter operation. 我可怜的人的解决方案是在更改操作之前和之后都有一个表来存储将要更改的表的结构。 That way, I could compare both structures and figure out what happened to which column(s). 这样,我可以比较这两种结构并弄清楚哪列发生了什么。

But before I do that, I was wondering if it is possible to do it using some other feature from SQL Server that I have overlooked, or maybe there's a better way. 但是在我这样做之前,我想知道是否可以使用我忽略的SQL Server其他功能来实现它,或者也许有更好的方法。 How would you go about this? 您将如何处理?

There is a product meant for doing just that (I wrote it). 有一种产品可以做到这一点(我写过)。
It monitors scripts that contained ddl changes, who wrote them and when together with their effect on performance, and it gives you the ability to easily copy them as one deployment script. 它监视包含ddl更改的脚本,编写脚本的人员以及更改的时间以及对性能的影响,它使您能够轻松地将它们复制为一个部署脚本。 For what you asked, the free version is sufficient. 对于您的要求,免费版本就足够了。
http://www.seracode.com/ http://www.seracode.com/

There is no special feature in SQL Server regarding your need. SQL Server中没有满足您需要的特殊功能。 You can use triggers, but they require a lot of T-SQL coding for proper function. 您可以使用触发器,但是它们需要大量的T-SQL编码才能正常运行。 Fast solution would be some third party tools, but they're not free. 快速解决方案将是一些第三方工具,但它们并非免费的。 Please take a look at this answer regarding the third party tools https://stackoverflow.com/a/18850705/2808398 请查看有关第三方工具的此答案https://stackoverflow.com/a/18850705/2808398

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

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