Yes, insert the GO command in between your scripts.
CREATE DATABASE MyDatabase
GO
USE [MyDatabase]
Question
I have a script which uses an existing database to create tables and enter values. Now I wish to create the database through this same script and then create the tables and values which are just a copy of another database.
I have:
CREATE DATABASE MyDatabase
USE [MyDatabase]
....Code that creates the tables and values from another database.
The USE [MyDatabase]
command is not recognized since MyDatabase does not exist anywhere yet. Is there a way around this?
Solution
Yes, insert the GO command in between your scripts.
CREATE DATABASE MyDatabase
GO
USE [MyDatabase]