Results 1 to 10 of 10

Thread: "Object ALready Exists" Error

  1. #1
    Join Date
    Apr 2013
    Posts
    6

    "Object ALready Exists" Error

    I am getting sick and tired of always getting the "Object ALready Exists" error after every "select from......." query on a table!! I slightly rename [both] the database and the table and I get the query results but I am tired of doing this. (I know that I can drop the database/table too and then recreate it) Can someone help me with this problem?

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Can you postwhole query?

  3. #3
    Join Date
    Apr 2013
    Posts
    6
    yes here is the query [in its' entirety].
    USE [Steves_Database]
    GO

    /****** Object: Table [dbo].[my_tbl] Script Date: 4/8/2013 9:49:46 AM ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    SET ANSI_PADDING ON
    GO

    CREATE TABLE [dbo].[my_tbl](
    [prod_id] [varchar](10) NOT NULL,
    [prod_desc] [varchar](40) NOT NULL,
    [cost] [decimal](6, 2) NOT NULL
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO

    and the error message:

    Msg 2714, Level 16, State 6, Line 2
    There is already an object named 'my_tbl' in the database.

  4. #4
    Join Date
    Apr 2013
    Posts
    6
    this is "database_steve" again and I noticed that you haven't responded back to me yet. Can you PLEASE tell me why I get this "object already exists" error message?? I am getting tired of adding a num. to a basic table name every time that I run a query to avoid seeing this error.

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    Why create table every time when you run query? You said you got error when run select statement in your original post but I didn't see any select in your code.

  6. #6
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    my_tbl can be any object including table, can you query sys.sysobjects table to see if anything exists with that name.

  7. #7
    Join Date
    Apr 2013
    Posts
    6
    you say this ".......but I didn't see any select in your code." well here is a full select statement for you with the same damn error message. I STILL need a "workaround" for this problem of mine which comtinues to me crazy.

    create database Stevies_Database;

    create table steves_table1
    (first_name varchar(10) not null,
    middle_name varchar(10) not null,
    last_name varchar(10) not null);

    select * from steves_table1;

    and here is the ensuing error message:

    Msg 1801, Level 16, State 3, Line 1
    Database 'Stevies_Database' already exists. Choose a different database name.
    Msg 2714, Level 16, State 6, Line 3
    There is already an object named 'steves_table1' in the database.

  8. #8
    Join Date
    Sep 2002
    Posts
    5,938
    Then again, why create db and table every time? You only need create them once. If you like to create them every time, have to drop db first.

  9. #9
    Join Date
    Apr 2013
    Posts
    6
    yes I difd the "select * from sys.sysobjects;" sql command and ended up getting a huge amount of results. Here they are [for your inspection].

    sp_MSalreadyhavegeneration -1073624922 P 4 0 0 0 0 0 2012-02-10 20:56:30.180 0 0 0 P 0 4 0 2012-02-10 20:56:30.180 0 0 0 0 0 2 0
    sp_MSwritemergeperfcounter -1072815163 P 4 0 0 0 0 0 2012-02-10 20:48:36.433 0 0 0 P 0 4 0 2012-02-10 20:48:36.433 0 0 0 0 0 2 0
    TABLE_PRIVILEGES -1072372588 V 3 0 0 0 0 0 2012-02-10 20:33:15.110 0 0 0 V 0 2 0 2012-02-10 20:33:15.110 0 0 0 0 0 2 0
    sp_replsetsyncstatus -1071944761 X 4 0 0 0 0 0 2012-02-10 20:38:49.730 0 0 0 X 0 4 0 2012-02-10 20:38:49.730 0 0 0 0 0 2 0
    sp_replshowcmds -1070913306 P 4 0 0 0 0 0 2012-02-10 20:44:07.697 0 0 0 P 0 4 0 2012-02-10 20:44:07.697 0 0 0 0 0 2 0
    sp_publishdb -1070573756 P 4 0 0 0 0 0 2012-02-10 20:39:35.560 0 0 0 P 0 4 0 2012-02-10 20:39:35.560 0 0 0 0 0 2 0
    sp_addqueued_artinfo -1068897509 P 4 0 0 0 0 0 2012-02-10 20:36:27.347 0 0 0 P 0 4 0 2012-02-10 20:36:27.347 0 0 0 0

  10. #10
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You first reported error about existing table, now you are reporting an error about existing database. You can't create a database if it already exists.

    Checking sysobjects is relevant if you think you don't have the table you are trying create. You can query sysobjects for the exact name match.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •