I am trying to write a code like this in T-SQL
BEGIN TRANSACTION
CREATE DATABASE DBName
USE DBName
BEGIN TRY
--Some sample query that could go wrong
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
I faced the error
DBName Database doesnt exist
This answer advised to use GO keyword (Click Here)
I faced the error
Syntax error near 'GO'
This answer tells that GO can't be used in T-SQL (Click Here)
I am using C# OleDBConnection to execute the SQL code
It works if I separately execute CREATE DATABASE first and then execute USE DBName in a separate file.
But in that case ROLLBACK would not rollback the database creation command and I will be left with a blank database. That is why, I need to include both CREATE DATABASE and USE DATABASE commands in the same file
How can I use something which is equivalent to GO keyword in T-SQL ?