Showing posts with label analyzer. Show all posts
Showing posts with label analyzer. Show all posts

Sunday, March 25, 2012

creating a table with select into

Hi,
how can i create a new table from a select statement? i use select into, but
my select query has case columns and query analyzer says that i did not
specified a column for them. how do i do it?
thanks in advance for your helpGive the column a name. Make this:
SELECT somecolum, CASE when x then y else z END
INTO #table
FROM table
look like this:
SELECT somecolum, CASE when x then y else z END AS SomeNewColumn
INTO #table
FROM table
or this:
SELECT somecolum, 'SomeNewColumn' = CASE when x then y else z END
INTO #table
FROM table
Keith
"Jose" <norespondais@.almailpor.favor> wrote in message
news:uNmJgiTDFHA.1396@.tk2msftngp13.phx.gbl...
> Hi,
> how can i create a new table from a select statement? i use select into,
but
> my select query has case columns and query analyzer says that i did not
> specified a column for them. how do i do it?
> thanks in advance for your help
>sql

Thursday, March 22, 2012

Creating a table inside a stored procedure

I am trying to creating a table inside a stored procedure using SQL that works fine in Query Analyzer. However, when I check the syntax I get the following message:

Error 208: Invalid object name '##OPTIONSEX'

I am using the following SQL script:

CREATE PROCEDURE [dbo].[Test2] AS

CREATE TABLE ##OPTIONSEX
(
OPTION_PLAN VARCHAR(50),
TOT_OPTIONS_EXCHANGED FLOAT NULL
)

GO

INSERT ##OPTIONSEX

SELECT
B.COMPONENT,
TOT_OPTIONS_EXCHANGED = SUM(A.UNITS)
FROM TBLEXERCISEOPTIONS A, TBLCOMPONENT B
WHERE B.COMPONENTID = A.COMPONENTID
GROUP BY B.COMPONENT

GO

Any help getting this to run correctly would be appreciated.Is that like the type of sex you want...is this mail order?

Anyway, you need to take out the GO...that's a scope terminator

And are you sure you want a GLOBAL Temp table instead of a local one?

Try this

CREATE PROCEDURE [dbo].[Test2]
AS
BEGIN
CREATE TABLE ##OPTIONSEX (
OPTION_PLAN VARCHAR(50)
, TOT_OPTIONS_EXCHANGED FLOAT NULL
)

INSERT ##OPTIONSEX
SELECT B.COMPONENT
, TOT_OPTIONS_EXCHANGED = SUM(A.UNITS)
FROM TBLEXERCISEOPTIONS A
INNER JOIN TBLCOMPONENT B
ON B.COMPONENTID = A.COMPONENTID
GROUP BY B.COMPONENT

DROP TABLE ##OPTIONSEX
GO|||Thanks for the reply. Worked fine only after I removed the BEGIN line. For some reason using BEGIN returned a syntax error.

Thanks again Brett.|||dooooooh

I forgot the END

BEGIN
.....some code
END

And you'll need those constructs if you do an control of flow logic

IF some condition
BEGIN
.........some code line 1
.........some code line 2
END

WHILE some Cond
BEGIN
.........some code line 1
.........some code line 2
END

Good luck

Sunday, March 11, 2012

Creating a new database

I am trying to create a new database, say name YYYData. I designed it in Vi
sio and created a .DDL file. When I opened the file in Query Analyzer and r
an it, I was informed there was a file already present named, YYYData. I tr
ied DROP database YYYData a
nd sp_dbremove YYYData and both times I was informed that YYYData does not e
xist.
What is wrong? How do it fix it?
Thanks.You will have to follow the identifier rule.
http://msdn.microsoft.com/library/d... />
3_6e9e.asp
e.g.
create database [YYYData]
-oj
http://www.rac4sql.net
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
quote:

> I am trying to create a new database, say name YYYData. I designed it in

Visio and created a .DDL file. When I opened the file in Query Analyzer and
ran it, I was informed there was a file already present named, YYYData. I
tried DROP database YYYData and sp_dbremove YYYData and both times I was
informed that YYYData does not exist.
quote:

> What is wrong? How do it fix it?
> Thanks.
|||This illustrates the dilemma:
-- IN SQL ANALYZER --
use master
go
create database [YYYData]
ON PRIMARY
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Da
ta\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 256 KB )
LOG ON
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Da
ta\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 256 KB )
go
use [YYYData]
go
--THE RESPONSE IN SQL ANALYZER --
Server: Msg 1828, Level 16, State 5, Line 4
The file named 'YYYData' is already in use. Choose another name.
Server: Msg 911, Level 16, State 1, Line 2
Could not locate entry in sysdatabases for database 'YYYData'. No entry foun
d with that name. Make sure that the name is entered correctly.
-- QUESTION --
How can YYYData be already in use in one place and not found immediately aft
er in another?
Thanks,
EagleRed
-- oj wrote: --
You will have to follow the identifier rule.
http://msdn.microsoft.com/library/d... />
3_6e9e.asp
e.g.
create database [YYYData]
-oj
http://www.rac4sql.net
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
quote:

> I am trying to create a new database, say name YYYData. I designed it in

Visio and created a .DDL file. When I opened the file in Query Analyzer and
ran it, I was informed there was a file already present named, YYYData. I
tried DROP database YYYData and sp_dbremove YYYData and both times I was
informed that YYYData does not exist.[QUOTE]|||> -- QUESTION --
quote:

> How can YYYData be already in use in one place and not found immediately

after in another?
Logical file names must be unique within a database. The CREATE DATABASE
statement should be something like:
CREATE DATABASE [YYYData]
ON PRIMARY
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
LOG ON
( NAME = YYYLog, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
Hope this helps.
Dan Guzman
SQL Server MVP
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:2A01B39B-8C77-4CFD-B95D-0C0155824361@.microsoft.com...
quote:

> This illustrates the dilemma:
> -- IN SQL ANALYZER --
> use master
> go
>
> create database [YYYData]
> ON PRIMARY
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL

Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
quote:

> LOG ON
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL

Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
quote:

> go
> use [YYYData]
> go
> --THE RESPONSE IN SQL ANALYZER --
> Server: Msg 1828, Level 16, State 5, Line 4
> The file named 'YYYData' is already in use. Choose another name.
> Server: Msg 911, Level 16, State 1, Line 2
> Could not locate entry in sysdatabases for database 'YYYData'. No entry

found with that name. Make sure that the name is entered correctly.
quote:

>
> -- QUESTION --
> How can YYYData be already in use in one place and not found immediately

after in another?
quote:

> Thanks,
> EagleRed
> -- oj wrote: --
> You will have to follow the identifier rule.
>

http://msdn.microsoft.com/library/d...con_03_6e9e.asp[QUOTE
]
> e.g.
> create database [YYYData]
>
> --
> -oj
> http://www.rac4sql.net
>
> "EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com>[/QUOTE]
wrote
quote:

> in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
it in[QUOTE]
> visio and created a .DDL file. When I opened the file in Query

Analyzer and
quote:

> ran it, I was informed there was a file already present named,

YYYData. I
quote:

> tried DROP database YYYData and sp_dbremove YYYData and both times I

was
quote:

> informed that YYYData does not exist.
>
>
|||The logical names for the data and log are the same - "NAME = YYYYData" is
used for both (but they must be unique)
Incidentally, the online help and BOL (Books On Line) have a complete
description of the syntax. Usually, this is the first place to start when
verifying syntax. In the description of create table, you will find:
logical_file_name
Is the name used to reference the file in any Transact-SQL statements
executed after the database is created. logical_file_name must be unique in
the database and conform to the rules for identifiers. The name can be a
character or Unicode constant, or a regular or delimited identifier.
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:2A01B39B-8C77-4CFD-B95D-0C0155824361@.microsoft.com...
quote:

> This illustrates the dilemma:
> -- IN SQL ANALYZER --
> use master
> go
>
> create database [YYYData]
> ON PRIMARY
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL

Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
quote:

> LOG ON
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL

Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
quote:

> go
> use [YYYData]
> go
> --THE RESPONSE IN SQL ANALYZER --
> Server: Msg 1828, Level 16, State 5, Line 4
> The file named 'YYYData' is already in use. Choose another name.
> Server: Msg 911, Level 16, State 1, Line 2
> Could not locate entry in sysdatabases for database 'YYYData'. No entry

found with that name. Make sure that the name is entered correctly.
quote:

>
> -- QUESTION --
> How can YYYData be already in use in one place and not found immediately

after in another?
quote:

> Thanks,
> EagleRed
> -- oj wrote: --
> You will have to follow the identifier rule.
>

http://msdn.microsoft.com/library/d...con_03_6e9e.asp[QUOTE
]
> e.g.
> create database [YYYData]
>
> --
> -oj
> http://www.rac4sql.net
>
> "EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com>[/QUOTE]
wrote
quote:

> in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
it in[QUOTE]
> visio and created a .DDL file. When I opened the file in Query

Analyzer and
quote:

> ran it, I was informed there was a file already present named,

YYYData. I
quote:

> tried DROP database YYYData and sp_dbremove YYYData and both times I

was
quote:

> informed that YYYData does not exist.
>
>
|||THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I canno
t create a database named YYYData because SQL Server says the name is in use
(not necessarily that a DB exists by that name). However, I cannot find it
on the list of databases o
n the server nor can I drop it or delete it with sp_dbremove. It seems I ha
ve a "zombie" DB that is dead but not gone. I would like to use the name YY
YData, since I have published the name in some documentation but I will chan
ge if I must. I would, how
ever, like to understand what is going on so I can at least avoid this probl
em in the future. I may have created a DB with this name in the past and de
leted it. I literally don't remember.
Thanks.
EagleRed|||I have consulted the docs and tried what was recommended there. But it isn't
working with a DB named YYYData. See my response to Dan Guzman for a bette
r description of my problem.
I appreciate your help!|||Re-read Dan's post. Your problem has NOTHING to do with an existing
database named YYYData - it is a problem with the logical names given to the
primary data file and the log file. Dan has chosen to use the logical name
of YYYData for the primary data file and the name of YYYLog for the log
file.
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:0D2C87AB-2B9D-49A0-A7BA-85E5EE6481F5@.microsoft.com...
quote:

> THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I

cannot create a database named YYYData because SQL Server says the name is
in use (not necessarily that a DB exists by that name). However, I cannot
find it on the list of databases on the server nor can I drop it or delete
it with sp_dbremove. It seems I have a "zombie" DB that is dead but not
gone. I would like to use the name YYYData, since I have published the name
in some documentation but I will change if I must. I would, however, like
to understand what is going on so I can at least avoid this problem in the
future. I may have created a DB with this name in the past and deleted it.
I literally don't remember.
quote:

> Thanks.
> EagleRed
|||create database [YYYData]
ON PRIMARY
( NAME = YYYData, /*first logical name*/
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.mdf',
SIZE = 3 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 256 KB )
LOG ON
( NAME = YYYData, /*second logical name*/
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.ldf',
SIZE = 1 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 256 KB )
The second logical name is where the error actually is. As stated, you
cannot have a duplicate logical name for a given database. You should change
the second one to something like YYYLog. Note: this has nothing to do with
the database name. It's just a logical name for the data or log file.
-oj
http://www.rac4sql.net
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:0D2C87AB-2B9D-49A0-A7BA-85E5EE6481F5@.microsoft.com...
quote:

> THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I

cannot create a database named YYYData because SQL Server says the name is
in use (not necessarily that a DB exists by that name). However, I cannot
find it on the list of databases on the server nor can I drop it or delete
it with sp_dbremove. It seems I have a "zombie" DB that is dead but not
gone. I would like to use the name YYYData, since I have published the name
in some documentation but I will change if I must. I would, however, like
to understand what is going on so I can at least avoid this problem in the
future. I may have created a DB with this name in the past and deleted it.
I literally don't remember.
quote:

> Thanks.
> EagleRed
|||Thanks, guys. I knew I was "holding my mouth wrong on something"! ENJOY!!!
!

Creating a new database

I am trying to create a new database, say name YYYData. I designed it in Visio and created a .DDL file. When I opened the file in Query Analyzer and ran it, I was informed there was a file already present named, YYYData. I tried DROP database YYYData and sp_dbremove YYYData and both times I was informed that YYYData does not exist.
What is wrong? How do it fix it?
Thanks.You will have to follow the identifier rule.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.asp
e.g.
create database [YYYData]
-oj
http://www.rac4sql.net
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
> I am trying to create a new database, say name YYYData. I designed it in
Visio and created a .DDL file. When I opened the file in Query Analyzer and
ran it, I was informed there was a file already present named, YYYData. I
tried DROP database YYYData and sp_dbremove YYYData and both times I was
informed that YYYData does not exist.
> What is wrong? How do it fix it?
> Thanks.|||This illustrates the dilemma
-- IN SQL ANALYZER -
use maste
g
create database [YYYData
ON PRIMAR
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 256 KB
LOG O
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 256 KB )
g
use [YYYData
g
--THE RESPONSE IN SQL ANALYZER -
Server: Msg 1828, Level 16, State 5, Line
The file named 'YYYData' is already in use. Choose another name
Server: Msg 911, Level 16, State 1, Line
Could not locate entry in sysdatabases for database 'YYYData'. No entry found with that name. Make sure that the name is entered correctly
-- QUESTION -
How can YYYData be already in use in one place and not found immediately after in another
Thanks
EagleRed
-- oj wrote: --
You will have to follow the identifier rule
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.as
e.g
create database [YYYData
--
-o
http://www.rac4sql.ne
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrot
in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com..
> I am trying to create a new database, say name YYYData. I designed it i
Visio and created a .DDL file. When I opened the file in Query Analyzer an
ran it, I was informed there was a file already present named, YYYData.
tried DROP database YYYData and sp_dbremove YYYData and both times I wa
informed that YYYData does not exist
>> What is wrong? How do it fix it
>> Thanks|||> -- QUESTION --
> How can YYYData be already in use in one place and not found immediately
after in another?
Logical file names must be unique within a database. The CREATE DATABASE
statement should be something like:
CREATE DATABASE [YYYData]
ON PRIMARY
( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
LOG ON
( NAME = YYYLog, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
--
Hope this helps.
Dan Guzman
SQL Server MVP
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:2A01B39B-8C77-4CFD-B95D-0C0155824361@.microsoft.com...
> This illustrates the dilemma:
> -- IN SQL ANALYZER --
> use master
> go
>
> create database [YYYData]
> ON PRIMARY
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
> LOG ON
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
> go
> use [YYYData]
> go
> --THE RESPONSE IN SQL ANALYZER --
> Server: Msg 1828, Level 16, State 5, Line 4
> The file named 'YYYData' is already in use. Choose another name.
> Server: Msg 911, Level 16, State 1, Line 2
> Could not locate entry in sysdatabases for database 'YYYData'. No entry
found with that name. Make sure that the name is entered correctly.
>
> -- QUESTION --
> How can YYYData be already in use in one place and not found immediately
after in another?
> Thanks,
> EagleRed
> -- oj wrote: --
> You will have to follow the identifier rule.
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.asp
> e.g.
> create database [YYYData]
>
> --
> -oj
> http://www.rac4sql.net
>
> "EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com>
wrote
> in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
> > I am trying to create a new database, say name YYYData. I designed
it in
> Visio and created a .DDL file. When I opened the file in Query
Analyzer and
> ran it, I was informed there was a file already present named,
YYYData. I
> tried DROP database YYYData and sp_dbremove YYYData and both times I
was
> informed that YYYData does not exist.
> >> What is wrong? How do it fix it?
> >> Thanks.
>
>|||The logical names for the data and log are the same - "NAME = YYYYData" is
used for both (but they must be unique)
Incidentally, the online help and BOL (Books On Line) have a complete
description of the syntax. Usually, this is the first place to start when
verifying syntax. In the description of create table, you will find:
logical_file_name
Is the name used to reference the file in any Transact-SQL statements
executed after the database is created. logical_file_name must be unique in
the database and conform to the rules for identifiers. The name can be a
character or Unicode constant, or a regular or delimited identifier.
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:2A01B39B-8C77-4CFD-B95D-0C0155824361@.microsoft.com...
> This illustrates the dilemma:
> -- IN SQL ANALYZER --
> use master
> go
>
> create database [YYYData]
> ON PRIMARY
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.mdf', SIZE = 3 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
> LOG ON
> ( NAME = YYYData, FILENAME = 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\YYYData.ldf', SIZE = 1 MB, MAXSIZE = UNLIMITED, FILEGROWTH
= 256 KB )
> go
> use [YYYData]
> go
> --THE RESPONSE IN SQL ANALYZER --
> Server: Msg 1828, Level 16, State 5, Line 4
> The file named 'YYYData' is already in use. Choose another name.
> Server: Msg 911, Level 16, State 1, Line 2
> Could not locate entry in sysdatabases for database 'YYYData'. No entry
found with that name. Make sure that the name is entered correctly.
>
> -- QUESTION --
> How can YYYData be already in use in one place and not found immediately
after in another?
> Thanks,
> EagleRed
> -- oj wrote: --
> You will have to follow the identifier rule.
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.asp
> e.g.
> create database [YYYData]
>
> --
> -oj
> http://www.rac4sql.net
>
> "EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com>
wrote
> in message news:C24DB8F9-BF60-4039-AFA9-E2A764B4E01D@.microsoft.com...
> > I am trying to create a new database, say name YYYData. I designed
it in
> Visio and created a .DDL file. When I opened the file in Query
Analyzer and
> ran it, I was informed there was a file already present named,
YYYData. I
> tried DROP database YYYData and sp_dbremove YYYData and both times I
was
> informed that YYYData does not exist.
> >> What is wrong? How do it fix it?
> >> Thanks.
>
>|||THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I cannot create a database named YYYData because SQL Server says the name is in use (not necessarily that a DB exists by that name). However, I cannot find it on the list of databases on the server nor can I drop it or delete it with sp_dbremove. It seems I have a "zombie" DB that is dead but not gone. I would like to use the name YYYData, since I have published the name in some documentation but I will change if I must. I would, however, like to understand what is going on so I can at least avoid this problem in the future. I may have created a DB with this name in the past and deleted it. I literally don't remember
Thanks
EagleRed|||Re-read Dan's post. Your problem has NOTHING to do with an existing
database named YYYData - it is a problem with the logical names given to the
primary data file and the log file. Dan has chosen to use the logical name
of YYYData for the primary data file and the name of YYYLog for the log
file.
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:0D2C87AB-2B9D-49A0-A7BA-85E5EE6481F5@.microsoft.com...
> THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I
cannot create a database named YYYData because SQL Server says the name is
in use (not necessarily that a DB exists by that name). However, I cannot
find it on the list of databases on the server nor can I drop it or delete
it with sp_dbremove. It seems I have a "zombie" DB that is dead but not
gone. I would like to use the name YYYData, since I have published the name
in some documentation but I will change if I must. I would, however, like
to understand what is going on so I can at least avoid this problem in the
future. I may have created a DB with this name in the past and deleted it.
I literally don't remember.
> Thanks.
> EagleRed|||create database [YYYData]
ON PRIMARY
( NAME = YYYData, /*first logical name*/
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.mdf',
SIZE = 3 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 256 KB )
LOG ON
( NAME = YYYData, /*second logical name*/
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\YYYData.ldf',
SIZE = 1 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 256 KB )
The second logical name is where the error actually is. As stated, you
cannot have a duplicate logical name for a given database. You should change
the second one to something like YYYLog. Note: this has nothing to do with
the database name. It's just a logical name for the data or log file.
--
-oj
http://www.rac4sql.net
"EagleRed@.highflyingbirds.com" <anonymous@.discussions.microsoft.com> wrote
in message news:0D2C87AB-2B9D-49A0-A7BA-85E5EE6481F5@.microsoft.com...
> THIS IS THE CRUX OF MY PROBLEM!!!!!!! This what I am experiencing. I
cannot create a database named YYYData because SQL Server says the name is
in use (not necessarily that a DB exists by that name). However, I cannot
find it on the list of databases on the server nor can I drop it or delete
it with sp_dbremove. It seems I have a "zombie" DB that is dead but not
gone. I would like to use the name YYYData, since I have published the name
in some documentation but I will change if I must. I would, however, like
to understand what is going on so I can at least avoid this problem in the
future. I may have created a DB with this name in the past and deleted it.
I literally don't remember.
> Thanks.
> EagleRed|||Thanks, guys. I knew I was "holding my mouth wrong on something"! ENJOY!!!!

Friday, February 17, 2012

Create was Alter

In query Analyzer I right click on a stored procedure and click edit. In the
pass it displayed ALTER and now it displays CREATE. How can I put it back?
Thanks,
DaveClick "Script Object to New Window As" > "CREATE" rather than "Edit".
Then you'll have to drop the proc before you can run the script, which
is why Edit puts in the ALTER statement instead of CREATE.
David Portas
SQL Server MVP
--|||Its just sql trying to helpful. It assumes as you are looking at it you abou
t
to change it, so it helpfully changes the create to an alter. I does not
effect you schema in any way.
You can prove this by scripting the database.
"Government does not solve problems; it subsidizes them."
Ronald Reagan
"Dave" wrote:

> In query Analyzer I right click on a stored procedure and click edit. In t
he
> pass it displayed ALTER and now it displays CREATE. How can I put it back?
> Thanks,
> Dave|||Apologies for the previous post, I must learn to read properly.
I take it that edit ->Script Object to New Window->alter doesn't work ?
"A politician needs the ability to foretell what is going to happen
tomorrow, next w, next month, and next year. And to have the ability
afterwards to explain why it didn't happen."
Winston Churchill
"Dave" wrote:

> In query Analyzer I right click on a stored procedure and click edit. In t
he
> pass it displayed ALTER and now it displays CREATE. How can I put it back?
> Thanks,
> Dave|||I ment when I click "Edit" I get CREATE now. I have been using the for years
and now it changed
"David Portas" wrote:

> Click "Script Object to New Window As" > "CREATE" rather than "Edit".
> Then you'll have to drop the proc before you can run the script, which
> is why Edit puts in the ALTER statement instead of CREATE.
> --
> David Portas
> SQL Server MVP
> --
>|||You may have made some subtle change to the spacing or
commenting of the beginning of the procedure. The script
generator identifies "create" naively and changes it to ALTER
where it is found. If you create the following procedures,
you'll see that pCREATE comes up with CREATE when
you edit it, pALTER comes up with ALTER when you
edit it, and oopsCREATE comes up with a wrong procedure
name oopsALTER when you edit it!
CREATE PROC pALTER (
@.i int
) as select 'pALTER'
go
CREATE
PROC pCREATE (
@.i int
) as select 'pCREATE'
go
CREATE
--
PROC oopsCREATE (
@.i int
) as select 'Oops!!'
go
-- Steve Kass
-- Drew University
Dave wrote:
>I ment when I click "Edit" I get CREATE now. I have been using the for year
s
>and now it changed
>"David Portas" wrote:
>
>|||It seems like they fixed that, Steve. I get ALTER in each case on
8.00.818.
David Portas
SQL Server MVP
--|||I had a comment directly above. I put a blank line in and then it worked.
Thanks Everyone,
Dave
"David Portas" wrote:

> It seems like they fixed that, Steve. I get ALTER in each case on
> 8.00.818.
> --
> David Portas
> SQL Server MVP
> --
>|||Strange. I'm also running 8.00.818, and I do not get ALTER in each case.
The object browser version must not be completely dependent on the
server version.
SK
David Portas wrote:

>It seems like they fixed that, Steve. I get ALTER in each case on
>8.00.818.
>
>