Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Drop database if exists issue

Author  Topic 

leozeo
Starting Member

2 Posts

Posted - 2009-08-14 : 06:51:09
I am trying to create a new database if it does not exists and if it exists then drop it and create it. I am trying to execute it from command line using .sql file as input.

But it is throwing error
"Could not locate entry in sysdatabases for database 'TEST_PUBLIC'. No entry found with that name. Make sure that the name is entered correctly."

The command which i have used is:
sqlcmd -S hostname,1433 -U abc -P xyz -i drop_database.sql

The content in drop_database.sql file is

USE MASTER
GO
IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='TEST_PUBLIC')
DROP DATABASE TEST_PUBLIC
GO
CREATE DATABASE TEST_PUBLIC
USE TEST_PUBLIC
GO


what modification i have to do in this script to make it working?

--
Leozeo

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-08-14 : 06:58:26
CREATE DATABASE TEST_PUBLIC
GO <<<--- Add this GO.
USE TEST_PUBLIC
GO
Go to Top of Page

leozeo
Starting Member

2 Posts

Posted - 2009-08-14 : 07:25:50
thanks yellowBug

crap i did a silly mistake!
Go to Top of Page
   

- Advertisement -