Solved

Deleting SQL Data

Posted on 2014-02-21
2
178 Views
Last Modified: 2014-02-21
I would like to know if there is a way that I can automate SQL data to be deleted.  Maybe once the database reaches a certain size then delete X amount or something like this.  I really don't know SQL and have 100's of servers that are running out of space from SQL databases.
0
Comment
Question by:MicahMcC
2 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
Comment Utility
There are some ways to make space without deleting any data, eg shrinking them, deleting logs.

DBCC SHRINKDATABASE is one.

If you are sure you can delete data, use DELETE queries, eg

DELETE FROM table WHERE somedatefield<DateAdd(year,-5, Getdate()) 

Open in new window

Would delete data older than 5 years according to somedatefield.

If you don't have datetime data in your table you won't be able to judge it's age, you will need to define the conditions for unimportant data differently, then.

Bye, Olaf.
0
 

Author Closing Comment

by:MicahMcC
Comment Utility
Olaf, thank you for the speedy response.  This will work as currently the servers that are filling up have approximately 4-7 years’ worth of data on them.  Thank you again!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

772 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

11 Experts available now in Live!

Get 1:1 Help Now