Pregunta

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?

¿Fue útil?

Solución

Yes, insert the GO command in between your scripts.

CREATE DATABASE MyDatabase
GO
USE [MyDatabase]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top