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?

Was it helpful?

Solution

Yes, insert the GO command in between your scripts.

CREATE DATABASE MyDatabase
GO
USE [MyDatabase]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top