Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 How do I delete all data in a table

Author  Topic 

Michael71
Posting Yak Master

126 Posts

Posted - 2007-01-17 : 16:04:27
How do I delete all data in a table and leave the data types and structure...please help...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-17 : 16:11:26
DELETE FROM YourTable -- this command is fully logged

or

TRUNCATE TABLE YourTable -- this command is partially logged and requires that no child constraints exist

Tara Kizer
Go to Top of Page

Michael71
Posting Yak Master

126 Posts

Posted - 2007-01-17 : 16:19:27
got this error...

Msg 208, Level 16, State 1, Line 1
Invalid object name 'PO_header'.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-17 : 16:26:42
You're probably in the wrong database then or that object doesn't exist.

The commands I gave you are correct.

Tara Kizer
Go to Top of Page

Michael71
Posting Yak Master

126 Posts

Posted - 2007-01-17 : 16:28:54
The table does exist. I'm looking at it.
Go to Top of Page

Michael71
Posting Yak Master

126 Posts

Posted - 2007-01-17 : 16:30:40
I was in the wrong database.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2007-01-17 : 19:07:16
ADVICE: Make sure you back up your data, your actions cant be reversed
Go to Top of Page

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2007-01-30 : 16:15:40
or use

BEGIN TRAN

-- Delete your stuff here

-- Check to make sure that you deleted what you wanted - no less no more

COMMIT -- If you are happy with deletions

ROLLBACK -- if you are not happy with deletions
Go to Top of Page
   

- Advertisement -