抱歉,是否曾经有人问过这个问题,但是这种情况并不常见。
我用一个.sql
文件处理很多助手查询,例如:
select * from elmah_error order by timeutc desc;
select * from orders order by timeutc desc;
我想防止使用F5执行整个文件,以便在按F5时仅执行“选择”。
我环顾了SQL Server Management Studio的所有设置,这些设置可能阻止“完整文件执行”并且找不到任何设置。
是否有和EXIT/BREAK/GOTOTOP
T-SQL命令,我可以在每个文件的顶部使用?
stop;
select * from elmah_error order by timeutc desc;
select * from orders order by timeutc desc;
非常感谢。
如果您的文件中没有执行任何批处理,而只有sql语句(即Sql语句)未用分隔GO
,则可以使用来修改文件,GOTO
并跳过您不想执行的语句。
但是,如果您确实在单独的批处理中包含了sql语句,那么它将无法正常工作。
/* Execute the following Statements */
PRINT 'Statement 1 executed'
PRINT 'Statement 2 executed'
GOTO SKIP_3; --<-- this will skip the statement 3 and will jump to "SKIP_3: Label"
/* Skip Statement 3 */
PRINT 'Statement 3 executed'
SKIP_3:
PRINT 'Statement 4 executed'
GOTO END_EXIT; --<-- Stop script execution here and jump to end
/* Execute Statement 5 and 6 */
PRINT 'Statement 5 executed'
PRINT 'Statement 6 executed'
END_EXIT:
结果
Statement 1 executed
Statement 2 executed
Statement 4 executed
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句