Are BEGIN/END needed in SQL scripts (in general) or is it fine to replace them with { and }
Example:
IF DB_ID('comics') IS NOT NULL
BEGIN
PRINT 'Database exists - dropping the comics database.';
DROP DATABASE comics;
END
VS
IF DB_ID('comics') IS NOT NULL
{
PRINT 'Database exists - dropping the comics database.';
DROP DATABASE comics;
}
I am using MS SQL Server 2008 R2
The documentation for
IF...ELSEshows:However, the Transact-SQL Syntax Conventions (Transact-SQL) page shows:
So, the braces aren’t something that you can enter in your code, but instead are simply showing that there is exactly one
sql_statementorstatement_blockrequired in anIFstatement. (Of course, astatement_blockcan contain multiplesql_statements as long as you useBEGINandENDaround them.)