Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored Procedure: There is already an object named '#columntable' in the database

Please see the code below:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE Test
AS
BEGIN
    begin
    select * into #dbreviews from dbreviews
    end

    drop table #dbreviews

    begin
    select * into #dbreviews from dbreviews
    end

END
GO

The error I get is:

There is already an object named '#dbreviews' in the database.

Questions like this: There is already an object named '#columntable' in the database are telling me this should be possible.

like image 273
w0051977 Avatar asked Jan 17 '26 22:01

w0051977


1 Answers

As per SQL Server specification, it is not allowed. Please refer to the documentation.

If more than one temporary table is created inside a single stored procedure or batch, they must have different names.

You are creating two temporary tables, with the same name #dbreviews. This is not allowed.

like image 196
rcs Avatar answered Jan 19 '26 11:01

rcs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!