Regularly execute SQL statements or stored procedures in SQL server. & SQL server automatically executes stored procedures

Source: Internet
Author: User

Reference to: http://msdn2.microsoft.com/zh-cn/library/ms178588 (VS.80). aspx
Regularly clear expired session data
Because the sample session state storage provider does not support Session_OnEnd events, it does not automatically clear expired session item data. We recommend that you use the following code to regularly Delete expired sessions in the data storage area.

String commandString = "delete from Sessions WHERE Expires <? "; 'Expires is the record time field in the table.
OdbcConnection conn = new OdbcConnection (connectionString );
OdbcCommand cmd = new OdbcCommand (commandString, conn );
Cmd. Parameters. Add ("@ Expires", OdbcType. DateTime). Value = DateTime. Now;
Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();

From: http://blog.csdn.net/amandar/archive/2006/03/03/614353.aspx
In the process of enterprise inventory management, some tasks need to be performed once every month or every day, such as backing up inventory at the end of the month as the initial value of the next month. The SQL AGENT provides this function to implement the task scheduling function in WINDOWS.

The prerequisite for using this technology is that the SQL AGENT service must be enabled.

First, create the task package to be executed in DTS.

Right-click a task package and select a scheduling package to define the time when the task needs to run. After confirmation, this task generates a record under the management, proxy scheduling, and job. You can see the next running time, last running time, and status on the record.

Note: You need to refresh the content of the management \ proxy scheduling \ job.

From: http://blog.csdn.net/czmtxz/archive/2006/07/21/953688.aspx

Sp_procoption
Set process options.

Syntax

Sp_procoption [@ ProcName =] 'processed'
, [@ OptionName =] 'option'
, [@ OptionValue =] 'value'

Parameters
[@ ProcName =] 'processed'

Is the process name for which you want to set or view options. Procedure is nvarchar (776) type and has no default value.

[@ OptionName =] 'option'

The name of the option to be set. The unique value of option is startup, which sets the automatic execution status of the stored procedure. A stored procedure that is set to automatically executed runs every time Microsoft SQL Server is started.

[, [@ OptionValue =] 'value']

Indicates whether the option is set to on (true or on) or off (false or off ). Value is of the varchar (12) type and has no default value.

Return code value
0 (successful) or error code (failed)

Permission
By default, the execution permission is granted to members of the sysadmin fixed server role. The startup process must belong to the master database owner.

Sp_procoption 'test', 'startup', 'on' enabled -- the test stored procedure is automatically executed every time the database is started.

Sp_procoption 'test', 'startup', 'off' disabled -- the test stored procedure is automatically executed every time the database is started.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.