2014-01-11 180 views
0

如果以前曾询问过这种情况,但情况并非如此。SQL Server Management Studio查询停止/退出

我有很多工作,有一个.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; 

非常感谢。

回答

3

如果您的文件中没有执行任何批处理,但只有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 
相关问题