From: Kris on
Hi There,

Hope I'm posting this to the right group. I'm trying to write a simple
script to create a database in SQL Server 2005. I keep getting the error
"Could not locate entry in sysdatabases for database 'testdb'. No entry found
with that name. Make sure that the name is entered correctly." Does anyone
know why this is occurring? I'm running it in SQL Server Management Studio if
that makes a difference.

create database testdb;
waitfor delay '00:00:05';
use testdb;
create table dbo.testtable(x INT primary key);
From: Tom Cooper on
The problem is that SQL parses the whole batch prior to running it. So when
it parses the "use testdb", testdb doesn't exist you. Instead of the delay,
do

create database testdb;
go
use testdb;
create table dbo.testtable(x INT primary key);

The go will cause SSMS to spilt this into two batches. So then the database
will be created, then SQL will see and parse the use statement and you will
have no problems.

Tom

"Kris" <Kris(a)discussions.microsoft.com> wrote in message
news:931742E0-A0AA-47F3-A1CE-E5FE2CB3AE57(a)microsoft.com...
> Hi There,
>
> Hope I'm posting this to the right group. I'm trying to write a simple
> script to create a database in SQL Server 2005. I keep getting the error
> "Could not locate entry in sysdatabases for database 'testdb'. No entry
> found
> with that name. Make sure that the name is entered correctly." Does anyone
> know why this is occurring? I'm running it in SQL Server Management Studio
> if
> that makes a difference.
>
> create database testdb;
> waitfor delay '00:00:05';
> use testdb;
> create table dbo.testtable(x INT primary key);

From: Kris on
Got it working - helps if I have the syntax right. :)

create database testdb
GO
use testdb
create table dbo.testtable(x INT primary key)


"Kris" wrote:

> Hi There,
>
> Hope I'm posting this to the right group. I'm trying to write a simple
> script to create a database in SQL Server 2005. I keep getting the error
> "Could not locate entry in sysdatabases for database 'testdb'. No entry found
> with that name. Make sure that the name is entered correctly." Does anyone
> know why this is occurring? I'm running it in SQL Server Management Studio if
> that makes a difference.
>
> create database testdb;
> waitfor delay '00:00:05';
> use testdb;
> create table dbo.testtable(x INT primary key);