Solved

Deleting SQL Data

Posted on 2014-02-21
2
179 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 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

16 Experts available now in Live!

Get 1:1 Help Now