Mega Code Archive

 
Categories / MSSQL Tutorial / Transact SQL
 

When multiple lines of code follow an IF statement it is best to wrap the lines in a BEGIN END block

7> 8> 9> CREATE PROCEDURE spTableExists 10>  @TableName VarChar(128) 11> AS 12>  IF EXISTS(SELECT * FROM sysobjects WHERE name = @TableName) 13>  BEGIN 14>   PRINT @TableName + ' exists' 15>   PRINT @TableName + ' exists' 16>  END 17>  ELSE 18>   PRINT @TableName + ' does not' 19> GO 1> 2> drop proc spTableExists; 3> GO