名站网址导航为大家提供关于数据库教程相关的教程网站知识。
核心导出作业的 具体相关代码 和 作业备份是相似的SQL_Server全文索引的使用实例演示
本文示范完整的SQL SERVER网站数据库全文索引以pubs网站数据库为例 首先,介绍利用系统存储过程创建全文索引的具体步骤: 1) 启动网站数据库的全文处理功能 (sp_fulltext_,---------********示例********------------- 以对pubs网站数据库的title和notes列建立全文索引,之后使用索引查询title列或notes列中包含有dateb,在这之前,需要安装Microsoft Search服务,启动SQL server全文搜索服务,复制具体相关代码 具体相关代码如下:,use pubs --打开网站数据库 go --检查网站数据库pubs是否支持全文索引,假如如果不支持 --则使用sp_fulltext_database 打开该功能 if(select database,过程名称:sp_fulltext_catalog 执行权限:db_owner及更高角色成员 作 用:创建和删除一个全文目录,启动或停止一个全文目录的索引操作办法,过程名称:sp_fulltext_database 执行权限:db_owner角色成员 作 用:初始化全文索引或删除网站数据库中所有全文目录,过程名称:sp_fulltext_table 执行权限:db_ddladnmin或db_owner角色成员 作 用:将一个表标识为全文索引表或非全文索引表,过程名称:sp_fulltext_column 执行权限:db_ddladnmin角色成员 作 用:指出一个全文索引表中的那些列假如或退出全文索引
复制具体相关代码 具体相关代码如下:
alter PROC DumpJob (@job VARChAR(100))
AS
DECLARE @retrun NVARChAR(max)
DECLARE @jobname VARChAR(30),@category_calss_i INT ,@category_calss VARChAR(50),@category_name VARChAR(50)
,@category_type VARChAR(30),@category_id int
,@category_type_i int
SELECT @jobname = 'powershell',@category_calss = '',@category_name='',@category_type = ''
SELECT @jobname = @job
SELECT @category_calss = CASE WhEN tshc.category_class = 1 ThEN 'JOB'
WhEN tshc.category_class = 2 ThEN 'ALERT'
else 'OPERATOR'
END
, @category_type = CASE WhEN tshc.category_type = 1 ThEN 'LOCAL'
WhEN tshc.category_type = 2 ThEN 'MULTI-SERVER'
else 'NONE'
END
,@category_name = tshc.name
,@category_type_i = category_type
,@category_calss_i = tshc.category_class
,@category_id = tshc.category_id
FROM
msdb.dbo.sysjobs_view AS sv
INNER JOIN msdb.dbo.syscategories AS tshc ON sv.category_id = tshc.category_id
WhERE
(sv.name=@jobname AND tshc.category_class = 1)
SET @retrun = ' BEGIN TRANSACTION'
SET @retrun = @retrun ChAR(13) ChAR(10) 'DECLARE @ReturnCode INT'
SET @retrun = @retrun ChAR(13) ChAR(10) 'IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WhERE name=N''' @category_name '''AND category_class=' rtrim(@category_calss_i) ')'
SET @retrun = @retrun ChAR(13) ChAR(10) 'BEGIN'
SET @retrun = @retrun ChAR(13) ChAR(10) 'EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N''' @category_calss ''', @type=N''' @category_type ''', @name=N''' @category_name ''''
SET @retrun = @retrun ChAR(13) ChAR(10) 'IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback'
SET @retrun = @retrun ChAR(13) ChAR(10) 'end'
DECLARE @EventLogLevel INT,@EmailLevel INT,@NetSendLevel INT,@PageLevel INT
DECLARE @EmailLeveloprid NVARChAR(256),@NetSendLeveloprid NVARChAR(256),@PageLeveloprid NVARChAR(256)
DECLARE @isenable INT , @description NVARChAR(1024),@owner_log_name Nvarchar(512),@delete_level INT
DECLARE @jobId UNIQUEIDENTIFIER,@start_step_id INT,@server NVARChAR(512)
SELECT
@EventLogLevel=sv.notify_level_eventlog
,@EmailLevel=sv.notify_level_email
,@NetSendLevel=sv.notify_level_netsend
,@PageLevel=sv.notify_level_page
,@EmailLeveloprid = ISNULL((SELECT TOP 1 name FROM msdb..sysoperators WhERE id = sv.notify_email_operator_id),'')
,@NetSendLeveloprid = ISNULL((SELECT TOP 1 name FROM msdb..sysoperators WhERE id = sv.notify_netsend_operator_id),'')
,@PageLeveloprid = ISNULL((SELECT TOP 1 name FROM msdb..sysoperators WhERE id = sv.notify_page_operator_id),'')
,@isenable = sv.enabled
,@description = sv.description
,@owner_log_name = ISNULL(suser_sname(sv.owner_sid), N'''')
,@delete_level = sv.delete_level
,@jobId = sv.job_id
,@start_step_id = start_step_id
,@server = originating_server
FROM msdb.dbo.sysjobs_view AS sv
WhERE (sv.name=@jobname and sv.category_id=0)
SET @retrun = @retrun ChAR(13) ChAR(10) 'DECLARE @jobId BINARY(16)'
SET @retrun = @retrun ChAR(13) ChAR(10) 'EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N''' @jobname ''','
SET @retrun = @retrun ChAR(13) ChAR(10) ' @enabled=' RTRIM(@isenable) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_level_eventlog=' RTRIM(@EventLogLevel) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_level_email=' RTRIM(@EmailLevel) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_level_netsend=' RTRIM(@NetSendLevel) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_level_page=' RTRIM(@PageLevel) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_email_operator_name =''' RTRIM(@EmailLeveloprid) ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_netsend_operator_name=''' RTRIM(@NetSendLeveloprid) ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @notify_page_operator_name=''' RTRIM(@PageLeveloprid) ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @delete_level=' RTRIM(@delete_level) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @description=N''' @description ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @category_name=N''' @category_name ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @owner_login_name=N''' @owner_log_name ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @job_id = @jobId OUTPUT'
SET @retrun = @retrun ChAR(13) ChAR(10) 'IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback'
--SELECT * FROM msdb.dbo.syscategories
DECLARE @step_id INT
declare @step_name nvarchar(512) ,@cmdexec_success_code INT,@on_success_action INT,@on_success_step_id INT
,@on_fail_action INT,@on_fail_step_id INT,@retry_attempts INT,@retry_interval INT,@os_run_priority INT
,@subsystem NVARChAR(512),@database_name NVARChAR(512),@flags INT,@command NVARChAR(max)
DECLARE jbcur CURSOR FOR SELECT step_id FROM msdb..sysjobsteps WhERE job_id = @jobid ORDER BY step_id ;
OPEN jbcur;
FETCh NEXT FROM jbcur INTO @step_id
WhILE @@FETCh_STATUS = 0
BEGIN
SELECT @step_name = step_name
,@cmdexec_success_code= cmdexec_success_code
,@on_success_action = on_success_action
,@on_success_step_id = on_success_step_id
,@on_fail_action = on_fail_action
,@on_fail_step_id = on_fail_step_id
,@retry_attempts = retry_attempts
,@retry_interval = retry_interval
,@os_run_priority = os_run_priority
,@subsystem = subsystem
,@database_name = database_name
,@command = command
,@flags = flags
FROM msdb..sysjobsteps a WhERE job_id = @jobid and step_id = @step_id
SET @retrun = @retrun ChAR(13) ChAR(10) ' EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @step_name=N''' @step_name ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @step_id=' RTRIM(@step_id) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @cmdexec_success_code=' RTRIM(@cmdexec_success_code) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @on_success_action=' RTRIM(@on_success_action) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @on_success_step_id=' RTRIM(@on_success_step_id) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @on_fail_action=' RTRIM(@on_fail_action) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @on_fail_step_id=' RTRIM(@on_fail_step_id) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @retry_attempts=' RTRIM(@retry_attempts) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @retry_interval=' RTRIM(@retry_interval) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @os_run_priority=' RTRIM(@os_run_priority) ', @subsystem=N''' @subsystem ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @database_name=N''' @database_name ''','
SET @retrun = @retrun ChAR(13) ChAR(10) ' @flags=' RTRIM(@flags) ' ,'
SET @retrun = @retrun ChAR(13) ChAR(10) ' @command=N''' REPLACE(@command,'''','''''') ''''
SET @retrun = @retrun ChAR(13) ChAR(10) ' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback'
FETCh NEXT FROM jbcur INTO @step_id
END
CLOSE jbcur
DEALLOCATE jbcur
SET @retrun = @retrun ChAR(13) ChAR(10) ' EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = ' rtrim(@start_step_id)
SET @retrun = @retrun ChAR(13) ChAR(10) ' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback '
DECLARE @enabled INT,@freq_type INT,@freq_interval INT,@freq_subday_type INT,@freq_subday_interval INT
,@freq_relative_interval INT,@freq_recurrence_factor INT,@active_start_date INT,@active_end_date INT
,@active_start_time INT,@active_end_time INT,@name VARChAR(512)
SELECT
@name = a.name
,@enabled = enabled
,@freq_interval = freq_interval
,@freq_type = freq_type
,@freq_subday_type=freq_subday_type
,@freq_subday_interval=freq_subday_interval
,@freq_relative_interval=freq_relative_interval
,@freq_recurrence_factor=freq_recurrence_factor
,@active_start_date=active_start_date
,@active_end_date=active_end_date
,@active_start_time=active_start_time
,@active_end_time=active_end_time
FROM msdb..sysschedules a
INNER JOIN msdb.dbo.sysjobschedules b ON a.schedule_id = b.schedule_id
WhERE job_id = @jobId
IF(@name IS not null)
begin
SET @retrun = @retrun ChAR(13) ChAR(10) ' EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N''' @name ''', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @enabled=' RTRIM(@enabled) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_type=' RTRIM(@freq_type) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_interval=' RTRIM(@freq_interval) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_subday_type=' RTRIM(@freq_subday_type) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_subday_interval=' RTRIM(@freq_subday_interval) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_relative_interval=' RTRIM(@freq_relative_interval) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @freq_recurrence_factor=' RTRIM(@freq_recurrence_factor) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @active_start_date=' RTRIM(@active_start_date) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @active_end_date=' RTRIM(@active_end_date) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @active_start_time=' RTRIM(@active_start_time) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @active_end_time=' RTRIM(@active_end_time) ', '
SET @retrun = @retrun ChAR(13) ChAR(10) ' @schedule_uid=N''' RTRIM(NEWID()) ''''
SET @retrun = @retrun ChAR(13) ChAR(10) ' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback'
END
SET @retrun = @retrun ChAR(13) ChAR(10) ' EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N''(local)'''
SET @retrun = @retrun ChAR(13) ChAR(10) ' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback'
SET @retrun = @retrun ChAR(13) ChAR(10) 'COMMIT TRANSACTION'
SET @retrun = @retrun ChAR(13) ChAR(10) 'GOTO EndSave'
SET @retrun = @retrun ChAR(13) ChAR(10) 'QuitWithRollback:'
SET @retrun = @retrun ChAR(13) ChAR(10) ' IF(@@TRANCOUNT>0)ROLLBACK TRANSACTION'
SET @retrun = @retrun ChAR(13) ChAR(10) 'EndSave:'
SET @retrun = @retrun ChAR(13) ChAR(10) ' '
select @retrun
我创建了一个存储过程,用来导出 作业,只有用powershell 脚本来实现同步,您可以powershell 脚本放入 sqlagent 中 定时运行起到同步的效果
一下是powershell 具体相关代码:
复制具体相关代码 具体相关代码如下:
关于数据库教程相关的教程网站知识今天我们就说到这里了,希望可以帮到大家。