SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Truncate table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lorellana
Starting Member

25 Posts

Posted - 09/24/2011 :  15:39:22  Show Profile  Reply with Quote
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 - 09/24/2011 :  15:40:44  Show Profile  Reply with Quote
I do not want to delete all records, only from a particular date.
Go to Top of Page

Kristen
Test

United Kingdom
22431 Posts

Posted - 09/24/2011 :  17:23:00  Show Profile  Reply with Quote
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

Edited by - Kristen on 09/24/2011 17:24:08
Go to Top of Page

GilaMonster
Flowing Fount of Yak Knowledge

South Africa
4507 Posts

Posted - 09/24/2011 :  17:59:01  Show Profile  Visit GilaMonster's Homepage  Reply with Quote
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

USA
73 Posts

Posted - 09/29/2011 :  10:18:08  Show Profile  Reply with Quote
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.


Edited by - Cindyaz on 12/06/2011 04:14:01
Go to Top of Page

anita.86
Starting Member

India
15 Posts

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

N/A
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000