Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Deleting SQL Data

Posted on 2014-02-21
2
Medium Priority
?
192 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 30

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 39878418
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
ID: 39878438
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

824 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