关于SQL的问题,存储过程的!
发布网友
发布时间:2022-04-09 10:50
我来回答
共1个回答
热心网友
时间:2022-04-09 12:19
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-99b8921d36c0'
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
打字不易,如满意,望采纳。
满意请采纳。追问没看懂啊,什么情况?