1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
| /****** Object: Database msdb Script Date: 27-6-2005 0:56:32 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'msdb')
DROP DATABASE [msdb]
GO
CREATE DATABASE [msdb] ON (NAME = N'MSDBData', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\msdbdata.mdf' , SIZE = 16, FILEGROWTH = 0) LOG ON (NAME = N'MSDBLog', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\msdblog.ldf' , FILEGROWTH = 0)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
exec sp_dboption N'msdb', N'autoclose', N'false'
GO
if( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) )
exec sp_dboption N'msdb', N'db chaining', N'true'
GO
use [msdb]
GO
/****** Object: Stored Procedure dbo.r_iRTblClassDefs Script Date: 27-6-2005 0:56:33 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[r_iRTblClassDefs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[r_iRTblClassDefs]
GO
/****** Object: Table [dbo].[RTblClassDefs] Script Date: 27-6-2005 0:56:33 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RTblClassDefs]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[RTblClassDefs]
GO
/****** Object: User dbo Script Date: 27-6-2005 0:56:32 ******/
/****** Object: User guest Script Date: 27-6-2005 0:56:32 ******/
if not exists (select * from dbo.sysusers where name = N'guest' and uid < 16382 and hasdbaccess = 1)
EXEC sp_grantdbaccess N'guest'
GO
/****** Object: DatabaseRole TargetServersRole Script Date: 27-6-2005 0:56:32 ******/
if not exists (select * from dbo.sysusers where name = N'TargetServersRole' and uid > 16399)
EXEC sp_addrole N'TargetServersRole'
GO
/****** Object: Table [dbo].[RTblClassDefs] Script Date: 27-6-2005 0:56:33 ******/
CREATE TABLE [dbo].[RTblClassDefs] (
[IntID] [binary] (8) NOT NULL ,
[Z_BranchID_Z] [int] NOT NULL ,
[Z_VS_Z] [int] NOT NULL ,
[Z_VE_Z] [int] NOT NULL ,
[ClassID] [binary] (16) NOT NULL ,
[VerPropDescs] [image] NULL ,
[PropDescs] [image] NULL ,
[ViewName] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ViewFlags] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_shipping_databases] Script Date: 27-6-2005 0:56:33 ******/
CREATE TABLE [dbo].[log_shipping_databases] (
[database_name] [sysname] NOT NULL ,
[maintenance_plan_id] [uniqueidentifier] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RTblClassDefs] WITH NOCHECK ADD
CONSTRAINT [RDexClassDefs] PRIMARY KEY CLUSTERED
(
[IntID],
[Z_BranchID_Z],
[Z_VS_Z]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[RTblClassDefs] ADD
CONSTRAINT [DF__RTblClass__PropD__7C1A6C5A] DEFAULT (null) FOR [PropDescs]
GO
CREATE UNIQUE INDEX [RDexClassDefsClass] ON [dbo].[RTblClassDefs]([ClassID], [Z_BranchID_Z], [Z_VS_Z]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
GRANT REFERENCES , SELECT , UPDATE , INSERT , DELETE ON [dbo].[RTblClassDefs] TO [RepositoryUser]
GO
/****** Object: Stored Procedure dbo.sp_set_sqlagent_properties Script Date: 27-6-2005 0:56:34 ******/
/**************************************************************/
/* SP_SET_SQLAGENT_PROPERTIES */
/**************************************************************/
CREATE PROCEDURE dbo.sp_set_sqlagent_properties
@auto_start INT = NULL, -- 1 or 0
-- Non-SQLDMO exposed properties
@sqlserver_restart INT = NULL, -- 1 or 0
@jobhistory_max_rows INT = NULL, -- No maximum = -1, otherwise must be > 1
@jobhistory_max_rows_per_job INT = NULL, -- 1 to @jobhistory_max_rows
@errorlog_file NVARCHAR(255) = NULL, -- Full drive\path\name of errorlog file
@errorlogging_level INT = NULL, -- 1 = error, 2 = warning, 4 = information
@error_recipient NVARCHAR(30) = NULL, -- Network address of error popup recipient
@monitor_autostart INT = NULL, -- 1 or 0
@local_host_server NVARCHAR(30) = NULL, -- Alias of local host server
@job_shutdown_timeout INT = NULL, -- 5 to 600 seconds
@cmdexec_account VARBINARY(64) = NULL, -- CmdExec account information
@regular_connections INT = NULL, -- 1 or 0
@host_login_name sysname = NULL, -- Login name (if regular_connections = 1)
@host_login_password VARBINARY(512) = NULL, -- Login password (if regular_connections = 1)
@login_timeout INT = NULL, -- 5 to 45 (seconds)
@idle_cpu_percent INT = NULL, -- 1 to 100
@idle_cpu_duration INT = NULL, -- 20 to 86400 seconds
@oem_errorlog INT = NULL, -- 1 or 0
@sysadmin_only INT = NULL, -- 1 or 0
@email_profile NVARCHAR(64) = NULL, -- Email profile name
@email_save_in_sent_folder INT = NULL, -- 1 or 0
@cpu_poller_enabled INT = NULL -- 1 or 0
AS
BEGIN
-- NOTE: We set all SQLServerAgent properties at one go for performance reasons.
-- NOTE: You cannot set the value of the properties msx_server_name, is_msx or
-- startup_account - they are all read only.
DECLARE @res_valid_range NVARCHAR(100)
DECLARE @existing_core_engine_mask INT
SET NOCOUNT ON
-- Remove any leading/trailing spaces from parameters
SELECT @errorlog_file = LTRIM(RTRIM(@errorlog_file))
-- Make sure values (if supplied) are good
IF (@auto_start IS NOT NULL)
BEGIN
-- NOTE: When setting the the services start value, 2 == auto-start, 3 == Don't auto-start
SELECT @auto_start = CASE @auto_start
WHEN 0 THEN 3
WHEN 1 THEN 2
ELSE 3 -- Assume non auto-start if passed a junk value
END
END
-- Non-SQLDMO exposed properties
IF (@monitor_autostart IS NOT NULL) AND ((@monitor_autostart < 0) OR (@monitor_autostart > 1))
BEGIN
RAISERROR(14266, -1, -1, '@monitor_autostart', '0, 1')
RETURN(1) -- Failure
END
IF (@job_shutdown_timeout IS NOT NULL) AND ((@job_shutdown_timeout < 5) OR (@job_shutdown_timeout > 600))
BEGIN
RAISERROR(14266, -1, -1, '@job_shutdown_timeout', '5..600')
RETURN(1) -- Failure
END
IF (@cpu_poller_enabled IS NOT NULL) AND ((@cpu_poller_enabled < 0) OR (@cpu_poller_enabled > 1))
BEGIN
RAISERROR(14266, -1, -1, 'cpu_poller_enabled', '0, 1')
RETURN(1) -- Failure
END
-- Write out the values
IF (@auto_start IS NOT NULL)
BEGIN
IF ((PLATFORM() & 0x1) = 0x1) -- NT
BEGIN
DECLARE @key NVARCHAR(200)
SELECT @key = N'SYSTEM\CurrentControlSet\Services\'
IF (SERVERPROPERTY('INSTANCENAME') IS NOT NULL)
SELECT @key = @key + N'SQLAgent$' + CONVERT (sysname, SERVERPROPERTY('INSTANCENAME'))
ELSE
SELECT @key = @key + N'SQLServerAgent'
EXECUTE master.dbo.xp_regwrite N'HKEY_LOCAL_MACHINE',
@key,
N'Start',
N'REG_DWORD',
@auto_start
END
ELSE
RAISERROR(14546, 16, 1, '@auto_start')
END
-- Non-SQLDMO exposed properties
IF (@jobhistory_max_rows IS NOT NULL)
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'JobHistoryMaxRows',
N'REG_DWORD',
@jobhistory_max_rows
DECLARE @OS int
EXECUTE master.dbo.xp_MSplatform @OS OUTPUT
IF (@regular_connections = 0)
BEGIN
IF (@OS = 2)
BEGIN
EXECUTE master.dbo.xp_instance_regdeletevalue N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'HostLoginID'
EXECUTE master.dbo.xp_instance_regdeletevalue N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'HostPassword'
END
ELSE
BEGIN
EXECUTE master.dbo.xp_sqlagent_param 2, N'HostLoginID'
EXECUTE master.dbo.xp_sqlagent_param 2, N'HostPassword'
END
END
IF (@host_login_password IS NOT NULL)
BEGIN
IF (@OS = 2)
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'HostPassword',
N'REG_BINARY',
@host_login_password
ELSE
END
IF (@login_timeout IS NOT NULL)
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'LoginTimeout',
N'REG_DWORD',
@login_timeout
IF (@sysadmin_only IS NOT NULL)
BEGIN
IF (@sysadmin_only = 1)
BEGIN
EXECUTE master.dbo.xp_sqlagent_proxy_account N'DEL'
END
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'SysAdminOnly',
N'REG_DWORD',
@sysadmin_only
END
IF (@email_profile IS NOT NULL)
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'EmailProfile',
N'REG_SZ',
@email_profile
IF (@email_save_in_sent_folder IS NOT NULL)
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'EmailSaveSent',
N'REG_DWORD',
@email_save_in_sent_folder
IF ((@existing_core_engine_mask IS NOT NULL) OR (@cpu_poller_enabled = 1))
BEGIN
IF (@cpu_poller_enabled = 1)
SELECT @cpu_poller_enabled = (ISNULL(@existing_core_engine_mask, 0) & ~32)
ELSE
SELECT @cpu_poller_enabled = (ISNULL(@existing_core_engine_mask, 0) | 32)
IF ((@existing_core_engine_mask IS NOT NULL) AND (@cpu_poller_enabled = 32))
EXECUTE master.dbo.xp_instance_regdeletevalue N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'CoreEngineMask'
ELSE
EXECUTE master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'CoreEngineMask',
N'REG_DWORD',
@cpu_poller_enabled
END
END
RETURN(0) -- Success
END
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/****** Object: Stored Procedure dbo.r_iRTblClassDefs Script Date: 27-6-2005 0:56:34 ******/
create procedure r_iRTblClassDefs @IntID binary(8), @Z_BranchID_Z int, @Z_VS_Z int, @ClassID binary(16), @VerPropDescs image, @PropDescs image=NULL, @Z_VE_Z int = 2147483647, @ViewName varchar(128)=NULL, @ViewFlags int = 0 as insert RTblClassDefs values (@IntID, @Z_BranchID_Z, @Z_VS_Z, @Z_VE_Z, @ClassID, @VerPropDescs, @PropDescs, @ViewName, @ViewFlags)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
GRANT EXECUTE ON [dbo].[r_iRTblClassDefs] TO [RepositoryUser]
GO |