简体   繁体   English

使用多种语句类型自动执行SQL脚本

[英]Automate SQL Script with Multiple Statement Types

I have a SQL script that works exactly as I want it to when I step through it line by line. 我有一个SQL脚本,当我逐行浏览它时,它可以完全按照我的意愿运行。 At first, this was a viable option, but the script has gotten larger over time and stepping through it now sucks. 最初,这是一个可行的选择,但是随着时间的推移,脚本变得越来越大,逐步执行它很烂。

I've tried to run the script as part of an SSIS package in Visual Studio, but that gave me weird results. 我试图在Visual Studio中将脚本作为SSIS包的一部分运行,但这给了我奇怪的结果。

I have a feeling this is because I have mixed language in the script, (ie multiple UPDATE, ALTER, SELECT INTO, statements) ... Is there a way to automate this script so it runs line by line as if I were stepping through it? 我觉得这是因为我在脚本中使用了多种语言(例如,多个UPDATE,ALTER,SELECT INTO,语句)... 是否有一种方法可以自动执行此脚本,所以它逐行运行,就像我在逐步执行一样它?

be kind. 善待。 and thank you! 谢谢你

Generally speaking. 一般来说。 All you need is a semi-colon after each statement, this is regardless of statement types. 您需要做的是在每个语句后加分号,而不论语句类型如何。 "Go" is only needed if you want to separate it into batches (although it might not work if you are passing the code through to something else, ie. ADO.NET command object). 仅当您要将其分成批次时才需要“运行”(尽管如果将代码传递给其他东西(例如ADO.NET命令对象),它可能不起作用)。 This is helpful if you want the code to continue running regardless of the success or failure of the code before the "go". 如果您希望代码继续运行,而不管代码“执行”之前是成功还是失败,这将很有帮助。 If you want the continuation of the code to depend upon the previous code just make sure to end each statement with a ";" 如果您希望代码的延续依赖于先前的代码,只需确保在每个语句后加一个“;”即可。

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

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