Showing posts with label sysobjects. Show all posts
Showing posts with label sysobjects. Show all posts

Tuesday, March 27, 2012

Cannot drop triggers using dynamic SQL

Hi,
I'm using:
SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
I've used this on a number of occaisions but it doesn't seem to be dropping
the triggers this time.
Can anybody think of what I may be doing wrong here?
Many thanks for any assistance in advance
AntHi Ant
This SELECT will generate DROP TRIGGER statements, but it will not execute
them to actually drop the triggers. You need to take the output and execute
it.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
> Hi,
> I'm using:
> SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> I've used this on a number of occaisions but it doesn't seem to be
> dropping
> the triggers this time.
> Can anybody think of what I may be doing wrong here?
> Many thanks for any assistance in advance
> Ant|||Hi Kalen,
Apoligies but you might have to walk me through that.
I tried:
exec(SELECT DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
)
but naturally I got an error.
How is this done?
Many thanks for your answer.
Ant
"Kalen Delaney" wrote:
> Hi Ant
> This SELECT will generate DROP TRIGGER statements, but it will not execute
> them to actually drop the triggers. You need to take the output and execute
> it.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://sqlblog.com
>
> "Ant" <Ant@.discussions.microsoft.com> wrote in message
> news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
> > Hi,
> > I'm using:
> >
> > SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> >
> > I've used this on a number of occaisions but it doesn't seem to be
> > dropping
> > the triggers this time.
> >
> > Can anybody think of what I may be doing wrong here?
> >
> > Many thanks for any assistance in advance
> >
> > Ant
>
>|||Ant
DECLARE @.DeleteTrigger nvarchar(4000)
DECLARE DeleteTrigger CURSOR LOCAL FAST_FORWARD
FOR
SELECT N'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
OPEN DeleteTrigger
WHILE 1 = 1
BEGIN
FETCH NEXT FROM DeleteTrigger INTO @.DeleteTrigger
IF @.@.FETCH_STATUS <> 0 BREAK
RAISERROR (@.DeleteTrigger , 0, 1) WITH NOWAIT
EXEC(@.DeleteTrigger)
END
CLOSE DeleteTrigger
DEALLOCATE DeleteTrigger
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:A03F503E-6EF6-47EA-BAEB-4E52857F6F98@.microsoft.com...
> Hi Kalen,
> Apoligies but you might have to walk me through that.
> I tried:
> exec(SELECT DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> )
> but naturally I got an error.
> How is this done?
> Many thanks for your answer.
> Ant
>
> "Kalen Delaney" wrote:
>> Hi Ant
>> This SELECT will generate DROP TRIGGER statements, but it will not
>> execute
>> them to actually drop the triggers. You need to take the output and
>> execute
>> it.
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>> www.InsideSQLServer.com
>> http://sqlblog.com
>>
>> "Ant" <Ant@.discussions.microsoft.com> wrote in message
>> news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
>> > Hi,
>> > I'm using:
>> >
>> > SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
>> >
>> > I've used this on a number of occaisions but it doesn't seem to be
>> > dropping
>> > the triggers this time.
>> >
>> > Can anybody think of what I may be doing wrong here?
>> >
>> > Many thanks for any assistance in advance
>> >
>> > Ant
>>|||Thank you.
Can this be done with Dynamic SQL? I'm sure I've done this before without
having to resort to using a Cursor(?)
"Uri Dimant" wrote:
> Ant
> DECLARE @.DeleteTrigger nvarchar(4000)
> DECLARE DeleteTrigger CURSOR LOCAL FAST_FORWARD
> FOR
> SELECT N'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> OPEN DeleteTrigger
> WHILE 1 = 1
> BEGIN
> FETCH NEXT FROM DeleteTrigger INTO @.DeleteTrigger
> IF @.@.FETCH_STATUS <> 0 BREAK
> RAISERROR (@.DeleteTrigger , 0, 1) WITH NOWAIT
> EXEC(@.DeleteTrigger)
> END
> CLOSE DeleteTrigger
> DEALLOCATE DeleteTrigger
>
>
> "Ant" <Ant@.discussions.microsoft.com> wrote in message
> news:A03F503E-6EF6-47EA-BAEB-4E52857F6F98@.microsoft.com...
> > Hi Kalen,
> >
> > Apoligies but you might have to walk me through that.
> >
> > I tried:
> >
> > exec(SELECT DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> > )
> >
> > but naturally I got an error.
> >
> > How is this done?
> >
> > Many thanks for your answer.
> > Ant
> >
> >
> >
> > "Kalen Delaney" wrote:
> >
> >> Hi Ant
> >>
> >> This SELECT will generate DROP TRIGGER statements, but it will not
> >> execute
> >> them to actually drop the triggers. You need to take the output and
> >> execute
> >> it.
> >>
> >> --
> >> HTH
> >> Kalen Delaney, SQL Server MVP
> >> www.InsideSQLServer.com
> >> http://sqlblog.com
> >>
> >>
> >> "Ant" <Ant@.discussions.microsoft.com> wrote in message
> >> news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
> >> > Hi,
> >> > I'm using:
> >> >
> >> > SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> >> >
> >> > I've used this on a number of occaisions but it doesn't seem to be
> >> > dropping
> >> > the triggers this time.
> >> >
> >> > Can anybody think of what I may be doing wrong here?
> >> >
> >> > Many thanks for any assistance in advance
> >> >
> >> > Ant
> >>
> >>
> >>
>
>|||Uri's solution IS dynamic SQL. Dynamic SQL means that we are building the
SQL command and then using EXEC to execute it, and he has this:
EXEC(@.DeleteTrigger)
I am assuming you are looking for a way to do it all with one statement.
You have not said what version you are using.
SQL 2000 has a procedures sp_execresultset that lets you execute the output
of another statement. This was not included in SQL 2005; I don't know why.
However, you should be able to get the definition of sp_execresultset from a
SQL 2000 server and create it in the master database of a SQL 2005 server
and get the same behavior.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:E46E8721-4815-4025-8C0E-D2092AF975DF@.microsoft.com...
> Thank you.
> Can this be done with Dynamic SQL? I'm sure I've done this before without
> having to resort to using a Cursor(?)
>
> "Uri Dimant" wrote:
>> Ant
>> DECLARE @.DeleteTrigger nvarchar(4000)
>> DECLARE DeleteTrigger CURSOR LOCAL FAST_FORWARD
>> FOR
>> SELECT N'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
>> OPEN DeleteTrigger
>> WHILE 1 = 1
>> BEGIN
>> FETCH NEXT FROM DeleteTrigger INTO @.DeleteTrigger
>> IF @.@.FETCH_STATUS <> 0 BREAK
>> RAISERROR (@.DeleteTrigger , 0, 1) WITH NOWAIT
>> EXEC(@.DeleteTrigger)
>> END
>> CLOSE DeleteTrigger
>> DEALLOCATE DeleteTrigger
>>
>>
>> "Ant" <Ant@.discussions.microsoft.com> wrote in message
>> news:A03F503E-6EF6-47EA-BAEB-4E52857F6F98@.microsoft.com...
>> > Hi Kalen,
>> >
>> > Apoligies but you might have to walk me through that.
>> >
>> > I tried:
>> >
>> > exec(SELECT DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
>> > )
>> >
>> > but naturally I got an error.
>> >
>> > How is this done?
>> >
>> > Many thanks for your answer.
>> > Ant
>> >
>> >
>> >
>> > "Kalen Delaney" wrote:
>> >
>> >> Hi Ant
>> >>
>> >> This SELECT will generate DROP TRIGGER statements, but it will not
>> >> execute
>> >> them to actually drop the triggers. You need to take the output and
>> >> execute
>> >> it.
>> >>
>> >> --
>> >> HTH
>> >> Kalen Delaney, SQL Server MVP
>> >> www.InsideSQLServer.com
>> >> http://sqlblog.com
>> >>
>> >>
>> >> "Ant" <Ant@.discussions.microsoft.com> wrote in message
>> >> news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
>> >> > Hi,
>> >> > I'm using:
>> >> >
>> >> > SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
>> >> >
>> >> > I've used this on a number of occaisions but it doesn't seem to be
>> >> > dropping
>> >> > the triggers this time.
>> >> >
>> >> > Can anybody think of what I may be doing wrong here?
>> >> >
>> >> > Many thanks for any assistance in advance
>> >> >
>> >> > Ant
>> >>
>> >>
>> >>
>>|||Hello Uri,
Thank you for this solution. I thought I'd exhaust all possiblities before
commiting to this. It does seem to ber the best one.
Much appreciated & sorry for the late reply
Ant
"Uri Dimant" wrote:
> Ant
> DECLARE @.DeleteTrigger nvarchar(4000)
> DECLARE DeleteTrigger CURSOR LOCAL FAST_FORWARD
> FOR
> SELECT N'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> OPEN DeleteTrigger
> WHILE 1 = 1
> BEGIN
> FETCH NEXT FROM DeleteTrigger INTO @.DeleteTrigger
> IF @.@.FETCH_STATUS <> 0 BREAK
> RAISERROR (@.DeleteTrigger , 0, 1) WITH NOWAIT
> EXEC(@.DeleteTrigger)
> END
> CLOSE DeleteTrigger
> DEALLOCATE DeleteTrigger
>
>
> "Ant" <Ant@.discussions.microsoft.com> wrote in message
> news:A03F503E-6EF6-47EA-BAEB-4E52857F6F98@.microsoft.com...
> > Hi Kalen,
> >
> > Apoligies but you might have to walk me through that.
> >
> > I tried:
> >
> > exec(SELECT DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> > )
> >
> > but naturally I got an error.
> >
> > How is this done?
> >
> > Many thanks for your answer.
> > Ant
> >
> >
> >
> > "Kalen Delaney" wrote:
> >
> >> Hi Ant
> >>
> >> This SELECT will generate DROP TRIGGER statements, but it will not
> >> execute
> >> them to actually drop the triggers. You need to take the output and
> >> execute
> >> it.
> >>
> >> --
> >> HTH
> >> Kalen Delaney, SQL Server MVP
> >> www.InsideSQLServer.com
> >> http://sqlblog.com
> >>
> >>
> >> "Ant" <Ant@.discussions.microsoft.com> wrote in message
> >> news:16961357-9B6B-4878-9E5C-47C532BAF8EA@.microsoft.com...
> >> > Hi,
> >> > I'm using:
> >> >
> >> > SELECT 'DROP TRIGGER ' + name FROM SYSOBJECTS WHERE type = 'TR'
> >> >
> >> > I've used this on a number of occaisions but it doesn't seem to be
> >> > dropping
> >> > the triggers this time.
> >> >
> >> > Can anybody think of what I may be doing wrong here?
> >> >
> >> > Many thanks for any assistance in advance
> >> >
> >> > Ant
> >>
> >>
> >>
>
>

Sunday, March 11, 2012

Cannot create a Stored Procedure

Hi,
I am getting a error that the object already exists in the database when I
try to create a Stored Procedure. I have looked in sysobjects table and have
tried 5-6 different names for the Stored Procedure but nothing works. Any
help will be greatly appreciated. Thanks.Can you show the CREATE PROCEDURE code, and the exact error message?
Did you verify that you are in the right database (SELECT DB_NAME()) and
that you are checking sysobjects in the correct database?
--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"sharman" <sharman@.discussions.microsoft.com> wrote in message
news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
> Hi,
> I am getting a error that the object already exists in the database when I
> try to create a Stored Procedure. I have looked in sysobjects table and
> have
> tried 5-6 different names for the Stored Procedure but nothing works. Any
> help will be greatly appreciated. Thanks.|||This is the Create Procedure Code:
if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[usp_ServerFullBackup_SystemDatabases]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_ServerFullBackup_SystemDatabases]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
AS
BEGIN
BACKUP DATABASE [master]
TO DISK = N'\\CurrentWeek\master.BAK'
WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
and this is the error message I get on the query analyzer:
Server: Msg 2714, Level 16, State 5, Procedure
usp_ServerFullBackup_SystemDatabases, Line 5
There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
the database.
and in the enterprise manager I get this message:
Microsoft SQL-DMO (ODBC SQLState: 42S01)
Error 2714: There is already an object named
'usp_ServerFullBackup_SystemDatabases' in the database
I tried querying the sysobjects table and the name of the Stored Proc is not
there. I even tried to create it with a name usp_XXX or usp_YYY and got the
same error message. Thanks.
"Aaron Bertrand [SQL Server MVP]" wrote:
> Can you show the CREATE PROCEDURE code, and the exact error message?
> Did you verify that you are in the right database (SELECT DB_NAME()) and
> that you are checking sysobjects in the correct database?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "sharman" <sharman@.discussions.microsoft.com> wrote in message
> news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
> > Hi,
> >
> > I am getting a error that the object already exists in the database when I
> > try to create a Stored Procedure. I have looked in sysobjects table and
> > have
> > tried 5-6 different names for the Stored Procedure but nothing works. Any
> > help will be greatly appreciated. Thanks.
>
>|||I also found out that it's only when I try to create the Stored Procedure in
the master database that I get this message. In all the other databases I am
able to create the Stored Procedure. I have tried different names but nothing
works.
"sharman" wrote:
> This is the Create Procedure Code:
> if exists (select * from dbo.sysobjects where id => object_id(N'[dbo].[usp_ServerFullBackup_SystemDatabases]')
> and OBJECTPROPERTY(id, N'IsProcedure') = 1)
> drop procedure [dbo].[usp_ServerFullBackup_SystemDatabases]
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
> AS
> BEGIN
> BACKUP DATABASE [master]
> TO DISK = N'\\CurrentWeek\master.BAK'
> WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
> END
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> and this is the error message I get on the query analyzer:
> Server: Msg 2714, Level 16, State 5, Procedure
> usp_ServerFullBackup_SystemDatabases, Line 5
> There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
> the database.
> and in the enterprise manager I get this message:
> Microsoft SQL-DMO (ODBC SQLState: 42S01)
> Error 2714: There is already an object named
> 'usp_ServerFullBackup_SystemDatabases' in the database
> I tried querying the sysobjects table and the name of the Stored Proc is not
> there. I even tried to create it with a name usp_XXX or usp_YYY and got the
> same error message. Thanks.
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
> > Can you show the CREATE PROCEDURE code, and the exact error message?
> >
> > Did you verify that you are in the right database (SELECT DB_NAME()) and
> > that you are checking sysobjects in the correct database?
> >
> > --
> > Aaron Bertrand
> > SQL Server MVP
> > http://www.sqlblog.com/
> > http://www.aspfaq.com/5006
> >
> >
> >
> >
> > "sharman" <sharman@.discussions.microsoft.com> wrote in message
> > news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
> > > Hi,
> > >
> > > I am getting a error that the object already exists in the database when I
> > > try to create a Stored Procedure. I have looked in sysobjects table and
> > > have
> > > tried 5-6 different names for the Stored Procedure but nothing works. Any
> > > help will be greatly appreciated. Thanks.
> >
> >
> >|||Could it be that it's a permissions problem? I have no problems creating
a Stored Proc in my master database.
That being said, I always prefer NOT to create any user defined objects
in my master database. I normally create an "administration" database
where I keep all my user objects. I think it too risky to mess to much
around in the Master database..:-).
--
Regards
Steen Schlüter Persson
Database Administrator / System Administrator
sharman wrote:
> I also found out that it's only when I try to create the Stored Procedure in
> the master database that I get this message. In all the other databases I am
> able to create the Stored Procedure. I have tried different names but nothing
> works.
> "sharman" wrote:
>> This is the Create Procedure Code:
>> if exists (select * from dbo.sysobjects where id =>> object_id(N'[dbo].[usp_ServerFullBackup_SystemDatabases]')
>> and OBJECTPROPERTY(id, N'IsProcedure') = 1)
>> drop procedure [dbo].[usp_ServerFullBackup_SystemDatabases]
>> GO
>> SET QUOTED_IDENTIFIER OFF
>> GO
>> SET ANSI_NULLS ON
>> GO
>> CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
>> AS
>> BEGIN
>> BACKUP DATABASE [master]
>> TO DISK = N'\\CurrentWeek\master.BAK'
>> WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
>> END
>> GO
>> SET QUOTED_IDENTIFIER OFF
>> GO
>> SET ANSI_NULLS ON
>> GO
>> and this is the error message I get on the query analyzer:
>> Server: Msg 2714, Level 16, State 5, Procedure
>> usp_ServerFullBackup_SystemDatabases, Line 5
>> There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
>> the database.
>> and in the enterprise manager I get this message:
>> Microsoft SQL-DMO (ODBC SQLState: 42S01)
>> Error 2714: There is already an object named
>> 'usp_ServerFullBackup_SystemDatabases' in the database
>> I tried querying the sysobjects table and the name of the Stored Proc is not
>> there. I even tried to create it with a name usp_XXX or usp_YYY and got the
>> same error message. Thanks.
>>
>>
>> "Aaron Bertrand [SQL Server MVP]" wrote:
>> Can you show the CREATE PROCEDURE code, and the exact error message?
>> Did you verify that you are in the right database (SELECT DB_NAME()) and
>> that you are checking sysobjects in the correct database?
>> --
>> Aaron Bertrand
>> SQL Server MVP
>> http://www.sqlblog.com/
>> http://www.aspfaq.com/5006
>>
>>
>> "sharman" <sharman@.discussions.microsoft.com> wrote in message
>> news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
>> Hi,
>> I am getting a error that the object already exists in the database when I
>> try to create a Stored Procedure. I have looked in sysobjects table and
>> have
>> tried 5-6 different names for the Stored Procedure but nothing works. Any
>> help will be greatly appreciated. Thanks.
>>

Cannot create a Stored Procedure

Hi,
I am getting a error that the object already exists in the database when I
try to create a Stored Procedure. I have looked in sysobjects table and have
tried 5-6 different names for the Stored Procedure but nothing works. Any
help will be greatly appreciated. Thanks.Can you show the CREATE PROCEDURE code, and the exact error message?
Did you verify that you are in the right database (SELECT DB_NAME()) and
that you are checking sysobjects in the correct database?
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"sharman" <sharman@.discussions.microsoft.com> wrote in message
news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
> Hi,
> I am getting a error that the object already exists in the database when I
> try to create a Stored Procedure. I have looked in sysobjects table and
> have
> tried 5-6 different names for the Stored Procedure but nothing works. Any
> help will be greatly appreciated. Thanks.|||This is the Create Procedure Code:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].& #91;usp_ServerFullBackup_SystemDatabases
]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].& #91;usp_ServerFullBackup_SystemDatabases
]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
AS
BEGIN
BACKUP DATABASE [master]
TO DISK = N'\\CurrentWeek\master.BAK'
WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
and this is the error message I get on the query analyzer:
Server: Msg 2714, Level 16, State 5, Procedure
usp_ServerFullBackup_SystemDatabases, Line 5
There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
the database.
and in the enterprise manager I get this message:
Microsoft SQL-DMO (ODBC SQLState: 42S01)
Error 2714: There is already an object named
'usp_ServerFullBackup_SystemDatabases' in the database
I tried querying the sysobjects table and the name of the Stored Proc is not
there. I even tried to create it with a name usp_XXX or usp_YYY and got the
same error message. Thanks.
"Aaron Bertrand [SQL Server MVP]" wrote:

> Can you show the CREATE PROCEDURE code, and the exact error message?
> Did you verify that you are in the right database (SELECT DB_NAME()) and
> that you are checking sysobjects in the correct database?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "sharman" <sharman@.discussions.microsoft.com> wrote in message
> news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
>
>|||I also found out that it's only when I try to create the Stored Procedure in
the master database that I get this message. In all the other databases I am
able to create the Stored Procedure. I have tried different names but nothin
g
works.
"sharman" wrote:
[vbcol=seagreen]
> This is the Create Procedure Code:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].& #91;usp_ServerFullBackup_SystemDatabases
]')
> and OBJECTPROPERTY(id, N'IsProcedure') = 1)
> drop procedure [dbo].& #91;usp_ServerFullBackup_SystemDatabases
]
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
> AS
> BEGIN
> BACKUP DATABASE [master]
> TO DISK = N'\\CurrentWeek\master.BAK'
> WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
> END
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> and this is the error message I get on the query analyzer:
> Server: Msg 2714, Level 16, State 5, Procedure
> usp_ServerFullBackup_SystemDatabases, Line 5
> There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
> the database.
> and in the enterprise manager I get this message:
> Microsoft SQL-DMO (ODBC SQLState: 42S01)
> Error 2714: There is already an object named
> 'usp_ServerFullBackup_SystemDatabases' in the database
> I tried querying the sysobjects table and the name of the Stored Proc is n
ot
> there. I even tried to create it with a name usp_XXX or usp_YYY and got th
e
> same error message. Thanks.
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>|||Could it be that it's a permissions problem? I have no problems creating
a Stored Proc in my master database.
That being said, I always prefer NOT to create any user defined objects
in my master database. I normally create an "administration" database
where I keep all my user objects. I think it too risky to mess to much
around in the Master database..:-).
Regards
Steen Schlüter Persson
Database Administrator / System Administrator
sharman wrote:[vbcol=seagreen]
> I also found out that it's only when I try to create the Stored Procedure
in
> the master database that I get this message. In all the other databases I
am
> able to create the Stored Procedure. I have tried different names but noth
ing
> works.
> "sharman" wrote:
>

Cannot create a Stored Procedure

Hi,
I am getting a error that the object already exists in the database when I
try to create a Stored Procedure. I have looked in sysobjects table and have
tried 5-6 different names for the Stored Procedure but nothing works. Any
help will be greatly appreciated. Thanks.
Can you show the CREATE PROCEDURE code, and the exact error message?
Did you verify that you are in the right database (SELECT DB_NAME()) and
that you are checking sysobjects in the correct database?
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"sharman" <sharman@.discussions.microsoft.com> wrote in message
news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
> Hi,
> I am getting a error that the object already exists in the database when I
> try to create a Stored Procedure. I have looked in sysobjects table and
> have
> tried 5-6 different names for the Stored Procedure but nothing works. Any
> help will be greatly appreciated. Thanks.
|||This is the Create Procedure Code:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[usp_ServerFullBackup_SystemDatabases]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_ServerFullBackup_SystemDatabases]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
AS
BEGIN
BACKUP DATABASE [master]
TO DISK = N'\\CurrentWeek\master.BAK'
WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
and this is the error message I get on the query analyzer:
Server: Msg 2714, Level 16, State 5, Procedure
usp_ServerFullBackup_SystemDatabases, Line 5
There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
the database.
and in the enterprise manager I get this message:
Microsoft SQL-DMO (ODBC SQLState: 42S01)
Error 2714: There is already an object named
'usp_ServerFullBackup_SystemDatabases' in the database
I tried querying the sysobjects table and the name of the Stored Proc is not
there. I even tried to create it with a name usp_XXX or usp_YYY and got the
same error message. Thanks.
"Aaron Bertrand [SQL Server MVP]" wrote:

> Can you show the CREATE PROCEDURE code, and the exact error message?
> Did you verify that you are in the right database (SELECT DB_NAME()) and
> that you are checking sysobjects in the correct database?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "sharman" <sharman@.discussions.microsoft.com> wrote in message
> news:CB1B4D7C-34A2-4B89-8786-836B57054FDA@.microsoft.com...
>
>
|||I also found out that it's only when I try to create the Stored Procedure in
the master database that I get this message. In all the other databases I am
able to create the Stored Procedure. I have tried different names but nothing
works.
"sharman" wrote:
[vbcol=seagreen]
> This is the Create Procedure Code:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[usp_ServerFullBackup_SystemDatabases]')
> and OBJECTPROPERTY(id, N'IsProcedure') = 1)
> drop procedure [dbo].[usp_ServerFullBackup_SystemDatabases]
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> CREATE PROCEDURE [dbo].usp_ServerFullBackup_SystemDatabases
> AS
> BEGIN
> BACKUP DATABASE [master]
> TO DISK = N'\\CurrentWeek\master.BAK'
> WITH INIT , NOUNLOAD , NAME = N'master Backup', STATS = 25, FORMAT
> END
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
> and this is the error message I get on the query analyzer:
> Server: Msg 2714, Level 16, State 5, Procedure
> usp_ServerFullBackup_SystemDatabases, Line 5
> There is already an object named 'usp_ServerFullBackup_SystemDatabases' in
> the database.
> and in the enterprise manager I get this message:
> Microsoft SQL-DMO (ODBC SQLState: 42S01)
> Error 2714: There is already an object named
> 'usp_ServerFullBackup_SystemDatabases' in the database
> I tried querying the sysobjects table and the name of the Stored Proc is not
> there. I even tried to create it with a name usp_XXX or usp_YYY and got the
> same error message. Thanks.
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
|||Could it be that it's a permissions problem? I have no problems creating
a Stored Proc in my master database.
That being said, I always prefer NOT to create any user defined objects
in my master database. I normally create an "administration" database
where I keep all my user objects. I think it too risky to mess to much
around in the Master database..:-).
Regards
Steen Schlüter Persson
Database Administrator / System Administrator
sharman wrote:[vbcol=seagreen]
> I also found out that it's only when I try to create the Stored Procedure in
> the master database that I get this message. In all the other databases I am
> able to create the Stored Procedure. I have tried different names but nothing
> works.
> "sharman" wrote: