Coding Villa Forum
FAQs
Advertisements

Event to delete expired data from DataBase Table.

Iram Online 7/4/2012 3:20:00 PM

Hello Friends!

I am working on a website and I want to create an event to delete all expired data from database tables automatically. As huge amount of data will be uploaded on that website daily.Therefore, I want to delete all expired data to improve performance.Please friends need your guidance to solve that problem.

Thanks

Share with Friends

Advertisements

Answer

Mehmood Online 7/5/2012 1:31:49 PM

There is not such type of event yet.

The concept of events relates to objects.

for example :
If you see the web or windows ' control that have particular events as web page or winform have certain events.

Loading , Loaded and other.

Dropdownlist control has selectionChanged event.

We could create our own events but how ' ll you trigger them daily automatically
?

You could create window service in visual studio for such type of tasks.

Or you may add your required program in Windows Task Scheduler ?

Or you have one more better option to create a sql job .

Sql job will trigger automatically at your specified time and is a component of sql server

Answer

Zaryab Online 7/5/2012 1:39:55 PM

Hi,

Can you provide any sample for SQL Job?

Thanks.

Answer

Mehmood Online 7/5/2012 1:40:30 PM

Other major thing is that do you think that performance will be enhanced from the revomal of records?

If thinking then its wrong.

Your database performance could be more slow but why?


Because your database log size increases when you delete .


You 'll have to reduce the database log size and should update the specified tables' statistics and rebuilding the indexes.


Keep an eyes on. The mentioned things and create such procedure and place it in sql job.

If Windows service then manage it by calling that stored procedure.

Answer

Mehmood Online 7/5/2012 1:41:36 PM

In case of Any ambiguty , ask

Answer

Mehmood Online 7/5/2012 3:51:29 PM

This is simple wizard approach.

You ll just need to follow some steps.

Right now I am. Unable to publish anything but I 'll try sooner INSA.

Anything else is required except of it?

So that I could try to put a complete scenario.

Answer

Zaryab Online 7/5/2012 7:59:28 PM

Ok Please Thanks.

Answer

Mehmood Online 7/6/2012 7:47:55 AM

Sorry in delay , I hadn't an instance of sql server installed in my home machine.
It's just complete It's downloading now.

One thing I forgot to ask: sql job is a component of sql server enterprise edition only.

I don't think that you could be able use this component if you have an express or may be standard edition.

Answer

Mehmood Online 7/7/2012 2:20:45 PM

One small sample and some guidence has been placed at below URL:

http://sdrv.ms/MIQjls

Answer

Mehmood Online 7/7/2012 2:58:28 PM

========================================Shrink database and Shrink Log==========

For shrinking the database and log , we Set Recovery Model simple before shrinking

and then Set its FUll model after using the below commands as i mentioned below:



Alter database DatabaseName SET Recovery simple

use DATABASE

DBCC SHRINKFILE('DatabaseNamelog', 1)

dbcc shrinkdatabase(DatabaseName)

Alter database DatabaseName SET Recovery full


I would suggest that you should first read the below article for getting an overview that

what se should do or what not?


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=147587

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

http://blog.sqlauthority.com/2010/05/03/sql-server-shrinkfile-and-truncate-log-file-in-sql-server-2008/




==========================================Statistics and Re indexing===========

For the update statistics , you could use

USE [tempdb]
EXEC sp_UpdateStats for whole database.

you can use UpdateStatistics for single table too.

----------------------------Further details---------------------------------

http://www.mssqltips.com/sqlservertip/1606/execute-update-statistics-for-all-sql-server-databases/

http://weblogs.sqlteam.com/billg/archive/2010/12/02/script-to-update-statistics-with-time-window.aspx

http://blog.sqlauthority.com/2010/01/25/sql-server-find-statistics-update-date-update-statistics/

=============================re -indexing and statistics=====================

http://blog.sqlauthority.com/2007/01/31/sql-server-reindexing-database-tables-and-update-statistics-on-tables/

Share with Friends

Post reply

 

Enter This Code
Captcha
 

Subscribe

Email me when people reply


Subscribe to the