user3885166
user3885166

Reputation: 215

Database doesn't exist

I use sql server 2014 and with following piece of code:

if db_id('handel') is not null
    drop database handel;

create database handel;
use handel;

I get the error: Database 'handel' does not exist. Make sure that the name is entered correctly. on line use handel, which blows my mind a bit, as just a line before I create said database. Could anyone please help?

Upvotes: 1

Views: 1620

Answers (1)

knkarthick24
knkarthick24

Reputation: 3216

You missed GO Keyword:

if db_id('handel') is not null
    drop database handel;

create database handel;
GO
use handel;

Upvotes: 6

Related Questions