I'm a student of Procramming C# and now I'm reading SQL.
First I loved to use this code to create and use database at a time:
--Create database CREATE DATABASE Library GO --Use Database USE Library GO
after that, I learned "if exists()" and I applied this code:
--Create database IF NOT EXISTS (SELECT * FROM sys.databases where name = 'Library') CREATE DATABASE Library ELSE PRINT 'The Library database is alreary exists!!' GO --Use Database USE Library GO
But now I want to create and use within a batch like this code:
--Create AND Use database IF NOT EXISTS (SELECT * FROM sys.databases where name = 'Library') BEGIN CREATE DATABASE Library USE Library END ELSE BEGIN USE Library END GO
But here is a problem

How can I do this at a time, please Help me
--
Best regards
ehsan