recreating Creating a Database

  • Hello

    When i try to recreate a database i get the following error messgae:

    There is already an object named 'Office' in the database.

    What can i do?

  • Presumably you are recreating the database + objects from scripts. Check your scripts for the duplicate object (probably a table, so look for CREATE TABLE statements). See if they are the same structure/code. If so, remove the duplicate. If not, find who provided the scripts & get them to explain/fix.



    Scott Duncan

    MARCUS. Why dost thou laugh? It fits not with this hour.
    TITUS. Why, I have not another tear to shed;
    --Titus Andronicus, William Shakespeare


  • Am using the go statement after each create table statement do you think that is the problem.

  • Nope. Nothing wrong with that. Like I wrote above, check for a duplicate CREATE statement - it's likely that two of them will have the same name 'Office'. E.g. CREATE TABLE Office or CREATE PROCEDURE Office et al.



    Scott Duncan

    MARCUS. Why dost thou laugh? It fits not with this hour.
    TITUS. Why, I have not another tear to shed;
    --Titus Andronicus, William Shakespeare


  • Check for the existence of the table for creating it

    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TABLENAME]') AND type in (N'U'))

    BEGIN

    CREATE TABLE TABLENAME

    (

    COL1 INT,

    COL2 VARCHAR(10)

    )

    END

    GO

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply