Truncate MSSQL data that is from 2011 and prior

Posted on 2012-08-21
Last Modified: 2012-08-21
I am running a MSSQL 2005 database on a 2003R2 server that is getting too large for the server. I have been asked to truncate all data that is older than December of 2011.

I have not heard of doing this and have not been able to find out how to accomplish the task.

Any suggestions
Question by:jimmylew52
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    you need to know/understand the table schema to know how to do this.
    some (transaction) tables will have datetime columns which indicate this, and you can then delete those rows, for example:
    DELETE yourtable WHERE datetimecol <= CONVERT(datetime, '2012-01-01', 120)
    LVL 2

    Expert Comment

    If the table doesn't have that sort of field, you can try to find a reasonable number of records to purge and purge them. Then, alter the table so that it has a "date modified" field and attach a trigger on inserts and updates to update that "date modified" field. Once you do that, you will have a reliable way of tracking when a record was last touched and you can routinely purge old records.
    LVL 1

    Author Comment

    Not all of the tables have a date/time column. Can this not be done then? Is there some way of splitting off the older data? The size of the data base is becoming a problem.
    LVL 142

    Accepted Solution

    "older data" only makes sense if you DO have a column that indicates the date/age.
    without that, impossible to do this (unless of course someone can look at the data and knows what could be deleted)

    but then again, if this is a third-party application, you shall NEVER start deleting in the db directly. you shall contact the third-party to help you.
    LVL 1

    Author Comment

    Thank You. Looks like this is not possible.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now