| |

VerySource

 Forgot password?
 Register
Search
View: 1022|Reply: 7

I want to write a stored procedure, everybody teaches me!

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-29 22:00:01
| Show all posts |Read mode
I want to write a stored procedure, which is to periodically insert and delete data into the database. Can it be achieved using stored procedures? How to do it, let's give an example ~
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-9 11:00:01
| Show all posts
Regularly insert and delete data into the database

It is recommended to call PROC with JOB
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-9 14:15:02
| Show all posts
It's better to use homework regularly ~
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-11 00:15:01
| Show all posts
It can be achieved with JOB.
Database Management New JOB1 sql: insert into tablename ...
New JOB2 sql: delete from tablename
Reply

Use magic Report

0

Threads

28

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-5-19 23:00:01
| Show all posts
Example of turning boss
IF EXISTS (SELECT * FROM msdb.dbo.sysjobs WHERE name = 'Enable pubs database')
EXEC msdb.dbo.sp_delete_job @ job_name = 'Enable pubs database'

--Define creation job
DECLARE @jobid uniqueidentifier
EXEC msdb.dbo.sp_add_job
@job_name = N 'Enable the pubs database',
@job_id = @jobid OUTPUT

-Define job steps
DECLARE @sql nvarchar (400), @ dbname sysname
SELECT @ dbname = N'master ', --Online or offline database can only be performed in the master database
@ sql = N'ALTER DATABASE pubs SET ONLINE '-use pubs database online (enable)
EXEC msdb.dbo.sp_add_jobstep
@job_id = @jobid,
@step_name = N 'Enable pubs database processing',
@subsystem = 'TSQL',
@ database_name = @ dbname,
@command = @sql

--Create scheduling (using several job scheduling templates specifically defined later)
EXEC msdb..sp_add_jobschedule
@job_id = @jobid,
@name = N 'Enable pubs database processing scheduling',
@ freq_type = 4,
@ freq_interval = 1,
@ freq_subday_type = 0x1,
@ freq_subday_interval = 1,
@active_start_time = 075000-every day at 07:50

--Add target server
DECLARE @servername sysname
SET @ servername = CONVERT (nvarchar (128), SERVERPROPERTY (N'ServerName '))
EXEC msdb.dbo.sp_add_jobserver
@job_id = @jobid,
@server_name = @servername
Reply

Use magic Report

0

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-21 19:30:01
| Show all posts
Use homework
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-23 02:15:01
| Show all posts
Still don't quite understand ~
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-6-9 08:15:02
| Show all posts
You can also write a stored procedure, call him regularly in JOB
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list