重构数据库过程的最佳方法是什么?

时间:2022-09-15 21:08:55

I need to understand and clarify some T-SQL stored procedures that contain important business logic. Does anyone know of any tools, tips, tricks, or hints that can be used for unit testing so I can refactor this sql without breaking it?

我需要理解并澄清一些包含重要业务逻辑的T-SQL存储过程。有没有人知道可以用于单元测试的任何工具,提示,技巧或提示,所以我可以重构这个sql而不会破坏它?

5 个解决方案

#1


I use C# for unit testing stored procedures - that is way more efficient than T-SQL. The first link explains how to quickly generate unit tests.

我使用C#进行单元测试存储过程 - 这比T-SQL更有效。第一个链接解释了如何快速生成单元测试。

Close those Loopholes - Testing Stored Procedures

关闭那些漏洞 - 测试存储过程

Close These Loopholes - Testing Database Modifications

关闭这些漏洞 - 测试数据库修改

#2


Simon Harriyott suggests using TSqlUnit for this. There is more information about his process on his blog.

Simon Harriyott建议使用TSqlUnit。在他的博客上有关于他的过程的更多信息。

#3


If you have access to Visual Studio Team System Database Edition, then it comes with a bunch of unit-testing tools geared specifically for databases, as explained in this MSDN article.

如果您可以访问Visual Studio Team System Database Edition,那么它会附带一组专门针对数据库的单元测试工具,如本MSDN文章中所述。

#4


For help on refactoring itself (as opposed to getting it under test so you can refector), do not forget to check out Refactoring Databases (either the book or the website).

有关重构本身的帮助(而不是让它受到测试以便你可以反射),不要忘记查看重构数据库(书籍或网站)。

I did write tests for stored procedures with the calling code (in my case Java with dbunit), but I do not know how it would compare against other methods.

我确实用调用代码编写了存储过程的测试(在我的例子中是带有dbunit的Java),但我不知道它将如何与其他方法进行比较。

#5


why do you need to refactor?

你为什么需要重构?

Add a bunch of PRINT statements and manually run it from the Management Studio. If you print the proper info, you should be able to trace through the code and understand what is going on.

添加一堆PRINT语句并从Management Studio手动运行它。如果您打印正确的信息,您应该能够跟踪代码并了解正在发生的事情。

If you don't know what parameters to use, modify it to send the input parameters to a log file, then use those to run it manually.

如果您不知道要使用哪些参数,请将其修改为将输入参数发送到日志文件,然后使用它们手动运行它们。

#1


I use C# for unit testing stored procedures - that is way more efficient than T-SQL. The first link explains how to quickly generate unit tests.

我使用C#进行单元测试存储过程 - 这比T-SQL更有效。第一个链接解释了如何快速生成单元测试。

Close those Loopholes - Testing Stored Procedures

关闭那些漏洞 - 测试存储过程

Close These Loopholes - Testing Database Modifications

关闭这些漏洞 - 测试数据库修改

#2


Simon Harriyott suggests using TSqlUnit for this. There is more information about his process on his blog.

Simon Harriyott建议使用TSqlUnit。在他的博客上有关于他的过程的更多信息。

#3


If you have access to Visual Studio Team System Database Edition, then it comes with a bunch of unit-testing tools geared specifically for databases, as explained in this MSDN article.

如果您可以访问Visual Studio Team System Database Edition,那么它会附带一组专门针对数据库的单元测试工具,如本MSDN文章中所述。

#4


For help on refactoring itself (as opposed to getting it under test so you can refector), do not forget to check out Refactoring Databases (either the book or the website).

有关重构本身的帮助(而不是让它受到测试以便你可以反射),不要忘记查看重构数据库(书籍或网站)。

I did write tests for stored procedures with the calling code (in my case Java with dbunit), but I do not know how it would compare against other methods.

我确实用调用代码编写了存储过程的测试(在我的例子中是带有dbunit的Java),但我不知道它将如何与其他方法进行比较。

#5


why do you need to refactor?

你为什么需要重构?

Add a bunch of PRINT statements and manually run it from the Management Studio. If you print the proper info, you should be able to trace through the code and understand what is going on.

添加一堆PRINT语句并从Management Studio手动运行它。如果您打印正确的信息,您应该能够跟踪代码并了解正在发生的事情。

If you don't know what parameters to use, modify it to send the input parameters to a log file, then use those to run it manually.

如果您不知道要使用哪些参数,请将其修改为将输入参数发送到日志文件,然后使用它们手动运行它们。