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
 General SQL Server Forums
 New to SQL Server Administration
 Truncate table

Author  Topic 

lorellana
Starting Member

25 Posts

Posted - 2011-09-24 : 15:39:22
I would like to use the command:
use sybsecurity
go
truncate table sysaudits_01
but the where clause,
it's possible?
Thanks you.

lorellana
Starting Member

25 Posts

Posted - 2011-09-24 : 15:40:44
I do not want to delete all records, only from a particular date.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-24 : 17:23:00
Use DELETE rather than TRUNCATE if you want to delete specific records.

DELETE D
FROM MyTable AS D
WHERE MyDateColumn < 'yyyymmdd' -- the cutoff date

Take a backup first
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-09-24 : 17:59:01
If that's a large amount of rows, it may be necessary to do the delete in chunks, a few thousand rows at a time. If that's the case the delete takes a TOP clause. DELETE TOP (20000) FROM ...

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Cindyaz
Yak Posting Veteran

73 Posts

Posted - 2011-09-29 : 10:18:08
Truncate removes all rows from the table. There is no 'where' clause to it. Use Delete as suggested above to delete rows based on some condition.

Go to Top of Page

anita.86
Starting Member

21 Posts

Posted - 2011-12-09 : 02:40:26
truncate command delete all records, for particular record u have
use
DELETE FROM TABLENAME WHERE 'YOUR CONDITION'

N/A
Go to Top of Page
   

- Advertisement -