关于SQLSERVER的存储过程的几个题目..求解~!~~

发布网友 发布时间:2022-04-23 10:15

我来回答

2个回答

热心网友 时间:2022-04-11 17:14

1、
CREATE FUNCTION return_num
(@Class_Num varchar(20) )
RETURNS int
AS
BEGIN
RETURN ( select cout(*) from classmates where classnum=@Class_Num )
END

3、
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database 数据库名字' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database 数据库名字'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'备份数据库名字',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'每天上午数据库备份',
@category_name=N'Database 数据库名字',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'declare @strDate nvarchar(max);
set @strDate = N''D:\DataBaseAutoBackup\数据库名字_'' + Convert(nvarchar(8),getdate(),112) + N''.bak''

BACKUP DATABASE [数据库名字] TO DISK = @strDate WITH NOFORMAT, NOINIT, NAME = N''数据库名字_Dev-完整 数据库 备份'', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschele @job_id=@jobId, @name=N'Daily Backup',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120510,
@active_end_date=99991231,
@active_start_time=50000,
@active_end_time=235959,
@schele_uid=N'f90cfdc3-cb5d-4e19-9e93-99b21d36c0'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO追问大神,第二题怎么做啊?

追答个人能力有限,不好意思,只能帮你到这了。

热心网友 时间:2022-04-11 18:32

1、2题都是创建一个返回值是table的函数,就可以解决
3题是在企业管理器中,创建一个数据库维护计划可以解决

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com