中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

引鎖,重建任務

發布時間:2020-07-16 20:10:28 來源:網絡 閱讀:563 作者:51GT 欄目:MySQL數據庫

當使用數據庫管理功能下的維護計劃,建立索引失敗的情況下,使用代理執行作業的方式,比較實用的,代碼如下:
方法1:
USE [msdb]
GO

/** Object: Job [索引重建] Script Date: 2018-2-8 16:29:40 **/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/** Object: JobCategory [[Uncategorized (Local)]]] Script Date: 2018-2-8 16:29:40 **/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
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'[Uncategorized (Local)]',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/** Object: Step [索引] Script Date: 2018-2-8 16:29:40 **/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'索引',
@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'/物料表索引/
ALTER INDEX [PK_BD_MATERIAL] ON [dbo].[T_BD_MATERIAL] REBUILD PARTITION = ALL WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

ALTER INDEX [IDX_BD_MTRL_FMASTERID] ON [dbo].[T_BD_MATERIAL] REBUILD PARTITION = ALL WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

ALTER INDEX [IDX_BD_MTRL_COMBIN] ON [dbo].[T_BD_MATERIAL] REBUILD PARTITION = ALL WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)', @database_name=N'數據庫名稱', @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_jobschedule @job_id=@jobId, @name=N'計劃1',
@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=20180208,
@active_end_date=99991231,
@active_start_time=230000,
@active_end_time=235959, @schedule_uid=N'4e5e768f-a2b5-4042-9766-ba8e5ebbd42e'
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
方法2:
右擊索引,選擇重新生成,打開數據庫跟蹤,找到生成語句 ,把代碼粘貼到執行計劃中,推薦使用這種方式

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

绥芬河市| 大城县| 黄陵县| 张家口市| 齐齐哈尔市| 长乐市| 建瓯市| 富锦市| 唐海县| 邢台市| 南丹县| 齐齐哈尔市| 板桥市| 西峡县| 志丹县| 乌拉特前旗| 共和县| 阿巴嘎旗| 舞阳县| 林芝县| 北宁市| 阿城市| 新密市| 德庆县| 义马市| 永修县| 禹城市| 慈溪市| 三明市| 宁河县| 温泉县| 揭阳市| 左云县| 博湖县| 瑞昌市| 抚顺县| 遂平县| 赤城县| 文昌市| 阜新市| 泰兴市|