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 2008 Forums
 Transact-SQL (2008)
 purging data

Author  Topic 

smitha
Posting Yak Master

100 Posts

Posted - 2010-11-10 : 07:07:41
How to purge the 4 months old data when the data is continuously logging in sql tables?

Smitha

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-10 : 07:18:32
Do you have a column to decide how old a row is?
What is the datatype of that column?
Example data?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

smitha
Posting Yak Master

100 Posts

Posted - 2010-11-10 : 07:41:36
the datatype is date, time and numerics

Smitha
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-10 : 07:48:23
DELETE YourTable
WHERE YourDateColumn < DATEADD(MONTH,-4,GETDATE())

You can also check if the WHERE clause is ok by having a look at the selected data first

SELECT * FROM YourTable
WHERE YourDateColumn < DATEADD(MONTH,-4,GETDATE())



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-10 : 08:03:03
quote:
Originally posted by smitha

How to purge the 4 months old data when the data is continuously logging in sql tables?

Smitha



Have a look at CHANGE_TRACKING.

http://msdn.microsoft.com/en-us/library/bb964713.aspx

PBUH

Go to Top of Page

smitha
Posting Yak Master

100 Posts

Posted - 2010-11-11 : 03:01:11
is there any settings in sql database to purge the data, instead of writing the query

Smitha
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-11 : 03:07:00
quote:
Originally posted by smitha

is there any settings in sql database to purge the data, instead of writing the query

Smitha



Did you went through the link I posted?

PBUH

Go to Top of Page
   

- Advertisement -