Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Something fissy about DELETE Expand / Collapse
Author
Message
Posted Sunday, December 23, 2012 7:48 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 7:26 AM
Points: 268, Visits: 668
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.
Post #1399787
Posted Sunday, December 23, 2012 10:29 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:58 PM
Points: 20,705, Visits: 32,356
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 Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1399799
Posted Sunday, December 23, 2012 10:54 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 8:17 PM
Points: 17,729, Visits: 15,595
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1399802
Posted Sunday, December 23, 2012 11:18 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Friday, July 11, 2014 12:55 AM
Points: 729, Visits: 340
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

Post #1399804
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse