Something fissy about DELETE

  • I create a table as CREATE TABLE DEMO (A INT)

    Then i deleted it as follow

    DELETE DEMO

    I tried to again recreate the table using the same above statement, But it gave me the following error message

    Msg 2714, Level 16, State 6, Line 1

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

    Now over here i am trying to understand when i deleted the table using delete how is it showing me the error message.

  • Shadab Shah (12/23/2012)


    I create a table as CREATE TABLE DEMO (A INT)

    Then i deleted it as follow

    DELETE DEMO

    I tried to again recreate the table using the same above statement, But it gave me the following error message

    Msg 2714, Level 16, State 6, Line 1

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

    Now over here i am trying to understand when i deleted the table using delete how is it showing me the error message.

    DELETE does not drop a table, it is used to delete records from a table. To drop a table you use DROP TABLE tablename;.

  • Lynn is correct. If you need to remove the table, you need to use DROP. If you are only trying to remove records, then DELETE is what you will use.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • When you run DELETE, every row will be removed from the table.

    TRUNCATE TABLE statement also removes all rows from a table. TRUNCATE TABLE has several advantages over DELETE, when used to remove all rows from a table. TRUNCATE TABLE uses less transaction log space, requires fewer locks, and leaves zero pages for the table.

    BUT Delete or Truncate does not remove Objects completely.Use DROP

    instead of Delete or Truncate.

    use DROP TABLE DEMO instead of Delete or Truncate

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

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