SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Something fissy about DELETE


Something fissy about DELETE

Author
Message
Shadab Shah
Shadab Shah
Mr or Mrs. 500
Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)Mr or Mrs. 500 (531 reputation)

Group: General Forum Members
Points: 531 Visits: 798
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.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51312 Visits: 38684
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;.

Cool
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)
SQLRNNR
SQLRNNR
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40577 Visits: 18565
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

hcprasadv
hcprasadv
Right there with Babe
Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)Right there with Babe (779 reputation)

Group: General Forum Members
Points: 779 Visits: 342
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search