0

I'm new to SQL and have the follow problem:

I want 1 script where I create my database and its tables:

CREATE DATABASE TestDB;
USE TestDB
CREATE TABLE Customers
(
  CustomerID int NOT NULL,
  Company nvarchar(150) Not NULL,
  CONSTRAINT pk_CustomerID PRIMARY KEY (CustomerID)
);
// further tables with same scheme like 'Customers'

With this script, I always get the error: TestDB is not existing...

I use SQL Server Express 2008 and SQL Server Management Studio

Thanks for help!

3
  • 1
    just type "Go" before "Use TestDB" Commented Dec 22, 2014 at 13:51
  • Try add the GO keyword between commands. Commented Dec 22, 2014 at 13:52
  • 1
    also see this stackoverflow.com/questions/2668529/… Commented Dec 22, 2014 at 13:54

1 Answer 1

1

Try this:

   CREATE DATABASE TestDB;
   GO
   USE TestDB
   GO
    CREATE TABLE Customers
    (
      CustomerID int NOT NULL,
      Company nvarchar(150) Not NULL,
      CONSTRAINT pk_CustomerID PRIMARY KEY (CustomerID)
    );
    // further tables with same scheme like 'Customers'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.