0

This is my script:

CREATE DATABASE mydbname;
USE mydbname;

If I run 1st line, then 2nd line, it works OK.

If I run both together then I get this error:

Msg 911, Level 16, State 1, Line 3
Database 'mydbname' does not exist. Make sure that the name is entered correctly.

What is the correct way to write this script?

1 Answer 1

2

Use GO inbetween:

CREATE DATABASE mydbname;
GO
USE mydbname;
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.