home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0430 - 0439 / ibm0430-0439 / ibm0438.tar / ibm0438 / SQL42110.ZIP / SQL421A.010 / SQL / I386 / INSTNT.SQ@ / INSTNT.SQ@
Encoding:
Text File  |  1994-07-14  |  12.0 KB  |  479 lines

  1. /*******************************************************************
  2. **
  3. **  This script file adds the WindowsNT specific settings and
  4. **  procedures.  It should be run after instmstr.sql has been run.
  5. **
  6. ********************************************************************/
  7.  
  8. use master
  9. go
  10.  
  11. /*
  12. ** Make sure we have enough space in master db to
  13. ** complete this script
  14. */
  15. dump tran master with truncate_only
  16. go
  17.  
  18. execute sp_configure 'update', 1
  19. go
  20. reconfigure with override
  21. go
  22.  
  23. /*
  24. ** Drop procedures that will be created by this script
  25. */
  26.  
  27. if exists ( select * from sysobjects
  28.         where sysstat & 7 = 4
  29.             and name = "MS_sqlctrs_users" )
  30.     drop proc MS_sqlctrs_users
  31. go
  32.  
  33. if exists ( select * from sysobjects
  34.         where sysstat & 7 = 4
  35.             and name = "MS_sqlctrs_locks" )
  36.     drop proc MS_sqlctrs_locks
  37. go
  38.  
  39. dump tran master with truncate_only
  40. go
  41.  
  42. if exists (select * from sysobjects
  43.         where sysstat & 7 = 4
  44.             and name = 'sp_addextendedproc')
  45.     drop procedure sp_addextendedproc
  46. go
  47.  
  48. if exists (select * from sysobjects
  49.         where sysstat & 7 = 4
  50.             and name = 'sp_dropextendedproc')
  51.     drop procedure sp_dropextendedproc
  52. go
  53.  
  54. if exists (select * from sysobjects
  55.         where sysstat & 7 = 4
  56.             and name = 'sp_helpextendedproc')
  57.     drop procedure sp_helpextendedproc
  58. go
  59.  
  60. dump tran master with truncate_only
  61. go
  62.  
  63. /*
  64. ** Delete messages that will be added by this script
  65. */
  66. delete from sysmessages
  67.     where error in (114,227,423,1708,3609,5016,5017,7964,7965,7966,8113)
  68. go
  69. delete from sysmessages where error between 4027 and 4034
  70. go
  71.  
  72. /*
  73. ** Add NT specific error messages.
  74. */
  75. insert into sysmessages
  76.    values (114, 15, 2, "Browse mode is invalid for a statement that assigns values to a variable", NULL)
  77. go
  78. insert into sysmessages
  79.    values (227, 16, 2, "Maximum number of vector aggregates exceeded (%d max, %d found).", NULL)
  80. go
  81. insert into sysmessages
  82.    values (423, 16, 2, "Too many substitution nodes in worktable. (MAX: %d, ACTUAL: %d). Try splitting query or limiting SELECT list.", NULL)
  83. go
  84. insert into sysmessages
  85.    values (1708, 15, 2, "The total row size, %d, for table '%.*s' exceeds the maximum number of bytes per row, %d.", NULL)
  86. go
  87. insert into sysmessages
  88.    values (3609, 10, 2, "Attempt to update a column in the fabricated row of an inner table in an outer join.", NULL)
  89. go
  90. insert into sysmessages
  91.    values (5016, 16, 2, "Database TEMPDB cannot be altered when in RAM.  Remove from RAM with 'sp_configure', stop\restart SQL Server, perform 'ALTER DATABASE', place in RAM with 'sp_configure', stop\restart SQL Server.", NULL)
  92. go
  93. insert into sysmessages
  94.    values (5017, 16, 2, "ALTER DATABASE failed.  Database %.*s not created with 'for load' option.", NULL)
  95. go
  96. insert into sysmessages
  97.    values (7964, 16, 2, "Allocation page SDES not open.", NULL)
  98. go
  99. insert into sysmessages
  100.    values (7965, 16, 2, "Page is not an allocation page.", NULL)
  101. go
  102. insert into sysmessages
  103.    values (7966, 10, 2, "WARNING: NO_INDEX option of '%.*s' being used, checks on non-system indexes will be skipped", NULL)
  104. go
  105. insert into sysmessages
  106.    values (8113,16,1,"Unable to recompile '%.*s', '%s %.*s' is illegal in an open transaction.", NULL)
  107. go
  108.  
  109. /*
  110. ** These are new messages for tape devices
  111. ** Messages 4027 - 4034
  112. */
  113. insert into sysmessages
  114.    values (4027, 16, 2, "Mount first tape for %s of database '%s'.", NULL)
  115. insert into sysmessages
  116.    values (4028, 10, 2, "End of tape has been reached, remove tape '%s' and mount next tape for %s of database '%s'.", NULL)
  117. insert into sysmessages
  118.    values (4029, 10, 2, "Database '%s'%s(%d pages) dumped to file <%d> on tape '%s'.", NULL)
  119. insert into sysmessages
  120.    values (4030, 16, 2, "Tape '%s' expires on day '%s' year '%s' and cannot be overwritten.", NULL)
  121. insert into sysmessages
  122.    values (4031, 16, 2, "Creation date on tape '%s'(%s) does not match that of first volume(%s).", NULL)
  123. insert into sysmessages
  124.    values (4032, 16, 2, "Cannot find file %d on tape '%s'.", NULL)
  125. insert into sysmessages
  126.    values (4033, 16, 2, "File <%d> on tape '%s' is not a SQL Server %s dump.", NULL)
  127. insert into sysmessages
  128.    values (4034, 16, 2, "Warning, file <%d> on tape '%s' was dumped from database '%s'.", NULL)
  129. go
  130.  
  131. /*
  132. ** Change the operating system version, user connections and memory
  133. ** parameter to the NT specific values.
  134. */
  135. update spt_values set name = "WINDOWS/NT"
  136. where name = "OS/2"
  137. update spt_values set high = 1048576
  138. where name = "memory"
  139. update spt_values set high = @@max_connections
  140. where name = "user connections"
  141. go
  142.  
  143. /*
  144. ** Add new sp_configure parameters for SQL Server/NT to spt_values
  145. ** and sysconfigures if they don't already exist.
  146. */
  147.  
  148. if not exists (select * from sysconfigures where config = 501)
  149.     insert sysconfigures values(501,  0, "TempDB in RAM option",0)
  150. if not exists (select * from spt_values where
  151.             number = 501 and type = 'C' and name = 'tempdb in ram')
  152.     insert spt_values(name, number, type, low, high)
  153.         values ("tempdb in ram", 501, 'C', 0, 1)
  154. go
  155.  
  156. if not exists (select * from sysconfigures where config = 502)
  157.     insert sysconfigures values(502,  8, "Maximum outstanding async IOs",0)
  158. if not exists (select * from spt_values where
  159.             number = 502 and type = 'C' and name = 'max async IO')
  160.     insert spt_values(name, number, type, low, high)
  161.         values ("max async IO", 502, 'C', 1, 50)
  162. go
  163.  
  164. if not exists (select * from sysconfigures where config = 503)
  165.     insert sysconfigures values(503,255, "Maximum worker threads",0)
  166. if not exists (select * from spt_values where
  167.             number = 503 and type = 'C' and name = 'max worker threads')
  168.     insert spt_values(name, number, type, low, high)
  169.         values ("max worker threads", 503, 'C', 10, 1024)
  170. go
  171.  
  172. dump tran master with truncate_only
  173. go
  174.  
  175. /*
  176. ** addextendedproc
  177. */
  178. create procedure sp_addextendedproc
  179. @functname varchar(30),        /* name of function to call */
  180. @dllname varchar(255)        /* name of DLL containing function */
  181. as
  182. /*
  183. **  If we're in a transaction, disallow the addition of the
  184. **  extended stored procedure.
  185. */
  186. if @@trancount > 0
  187. begin
  188.     print "Can't run sp_addextendedproc from within a transaction."
  189.     return (1)
  190. end
  191.  
  192. /*
  193. **  You must be SA to execute this sproc.
  194. */
  195. if suser_id() != 1
  196. begin
  197.     print "You must be the System Administrator (SA) to execute this procedure."
  198.     return (1)
  199. end
  200.  
  201. /*
  202. ** Create the extended procedure mapping.
  203. */
  204. dbcc addextendedproc( @functname, @dllname)
  205. return (0)
  206. go
  207.  
  208. dump tran master with truncate_only
  209. go
  210.  
  211. /*
  212. ** dropextendedproc
  213. */
  214. create procedure sp_dropextendedproc
  215. @functname varchar(30)        /* name of function */
  216. as
  217. /*
  218. **  If we're in a transaction, disallow the dropping of the
  219. **  extended stored procedure.
  220. */
  221. if @@trancount > 0
  222. begin
  223.     print "Can't run sp_dropextendedproc from within a transaction."
  224.     return (1)
  225. end
  226.  
  227. /*
  228. **  You must be SA to execute this sproc.
  229. */
  230. if suser_id() != 1
  231. begin
  232.     print "You must be the System Administrator (SA) to execute this procedure."
  233.     return (1)
  234. end
  235.  
  236. /*
  237. ** Drop the extended procedure mapping.
  238. */
  239. dbcc dropextendedproc( @functname )
  240. return (0)
  241. go
  242.  
  243. dump tran master with truncate_only
  244. go
  245.  
  246. /*
  247. ** Drop extended procs. if they already exist now that sp_dropextendedproc
  248. ** has be created.
  249. */
  250. if exists (select * from sysobjects
  251.         where sysstat & 7 = 4
  252.             and name = 'xp_logininfo')
  253.     exec sp_dropextendedproc 'xp_logininfo'
  254. go
  255.  
  256. if exists (select * from sysobjects
  257.         where sysstat & 7 = 4
  258.             and name = 'xp_loginconfig')
  259.     exec sp_dropextendedproc 'xp_loginconfig'
  260. go
  261.  
  262. if exists (select * from sysobjects
  263.         where sysstat & 7 = 4
  264.             and name = 'xp_grantlogin')
  265.     exec sp_dropextendedproc 'xp_grantlogin'
  266. go
  267.  
  268. dump tran master with truncate_only
  269. go
  270.  
  271. if exists (select * from sysobjects
  272.         where sysstat & 7 = 4
  273.             and name = 'xp_revokelogin')
  274.     exec sp_dropextendedproc 'xp_revokelogin'
  275.  
  276. if exists (select * from sysobjects
  277.         where sysstat & 7 = 4
  278.             and name = 'xp_cmdshell')
  279.     exec sp_dropextendedproc 'xp_cmdshell'
  280.  
  281. if exists (select * from sysobjects
  282.         where sysstat & 7 = 4
  283.             and name = 'xp_logevent')
  284.     exec sp_dropextendedproc 'xp_logevent'
  285. go
  286.  
  287. dump tran master with truncate_only
  288. go
  289.  
  290. if exists (select * from sysobjects
  291.         where sysstat & 7 = 4
  292.             and name = 'xp_enumgroups')
  293.     exec sp_dropextendedproc 'xp_enumgroups'
  294. go
  295.  
  296. if exists (select * from sysobjects
  297.         where sysstat & 7 = 4
  298.             and name = 'xp_startmail')
  299.     exec sp_dropextendedproc 'xp_startmail'
  300. go
  301.  
  302. if exists (select * from sysobjects
  303.         where sysstat & 7 = 4
  304.             and name = 'xp_stopmail')
  305.     exec sp_dropextendedproc 'xp_stopmail'
  306. go
  307.  
  308. if exists (select * from sysobjects
  309.         where sysstat & 7 = 4
  310.             and name = 'xp_sendmail')
  311.     exec sp_dropextendedproc 'xp_sendmail'
  312. go
  313.  
  314. if exists (select * from sysobjects
  315.         where sysstat & 7 = 4
  316.             and name = 'xp_mailproclist')
  317.     exec sp_dropextendedproc 'xp_mailproclist'
  318. go
  319.  
  320. if exists (select * from sysobjects
  321.         where sysstat & 7 = 4
  322.             and name = 'xp_loginmail')
  323.     exec sp_dropextendedproc 'xp_loginmail'
  324. go
  325.  
  326. if exists (select * from sysobjects
  327.         where sysstat & 7 = 4
  328.             and name = 'xp_prepmsg')
  329.     exec sp_dropextendedproc 'xp_prepmsg'
  330. go
  331.  
  332. if exists (select * from sysobjects
  333.         where sysstat & 7 = 4
  334.             and name = 'xp_addmsgline')
  335.     exec sp_dropextendedproc 'xp_addmsgline'
  336. go
  337.  
  338. if exists (select * from sysobjects
  339.         where sysstat & 7 = 4
  340.             and name = 'xp_addattach')
  341.     exec sp_dropextendedproc 'xp_addattach'
  342. go
  343.  
  344. if exists (select * from sysobjects
  345.         where sysstat & 7 = 4
  346.             and name = 'xp_sendmsg')
  347.     exec sp_dropextendedproc 'xp_sendmsg'
  348. go
  349.  
  350. if exists (select * from sysobjects
  351.         where sysstat & 7 = 4
  352.             and name = 'xp_logoffmail')
  353.     exec sp_dropextendedproc 'xp_logoffmail'
  354. go
  355.  
  356. if exists (select * from sysobjects
  357.         where sysstat & 7 = 4
  358.             and name = 'xp_msver')
  359.     exec sp_dropextendedproc 'xp_msver'
  360. go
  361.  
  362. /*
  363. ** helpextendedproc
  364. */
  365.  
  366. create procedure sp_helpextendedproc
  367. @funcname varchar(30) = NULL
  368. as
  369.  
  370. set nocount on
  371.  
  372. /*
  373. **  If no function name given, get 'em all.
  374. */
  375. if @funcname = null
  376.     select @funcname = "%"
  377.  
  378. /*
  379. **  Make sure the function name exists
  380. */
  381. if not exists (select *
  382.     from master.dbo.sysobjects
  383.         where type = "X "
  384.           and name like @funcname)
  385. begin
  386.     print "No such extended procedure name exists."
  387.     return (1)
  388. end
  389.  
  390. /*
  391. **  Now print out the function name info
  392. */
  393. select distinct name = master.dbo.sysobjects.name,
  394.         dll = substring(master.dbo.syscomments.text,1,30)
  395.             from master.dbo.sysobjects, master.dbo.syscomments
  396.         where master.dbo.sysobjects.id = master.dbo.syscomments.id
  397.           and master.dbo.sysobjects.name like @funcname
  398.           and master.dbo.sysobjects.type = "X "
  399.         order by master.dbo.sysobjects.name
  400.  
  401. return (0)
  402. go
  403.  
  404. grant execute on sp_helpextendedproc to public
  405. go
  406.  
  407. /*
  408. ** Add xp_cmdshell extended procedure
  409. */
  410. sp_addextendedproc 'xp_cmdshell','xpsql.dll'
  411. go
  412.  
  413. /*
  414. ** Add xp_logevent extended procedure
  415. */
  416. sp_addextendedproc 'xp_logevent','xpsql.dll'
  417. go
  418.  
  419. dump tran master with truncate_only
  420. go
  421.  
  422. /*
  423. ** Add xp_logevent extended procedure
  424. */
  425. sp_addextendedproc 'xp_msver','xpsql.dll'
  426. go
  427.  
  428. /*
  429. ** Add xp_enumgroups extended procedure
  430. */
  431. sp_addextendedproc 'xp_enumgroups','xplogin.dll'
  432. go
  433.  
  434. /*
  435. ** Add mail enabling extended procedures
  436. */
  437. sp_addextendedproc 'xp_startmail', 'sqlmapi.dll'
  438. go
  439. sp_addextendedproc 'xp_stopmail', 'sqlmapi.dll'
  440. go
  441. sp_addextendedproc 'xp_sendmail', 'sqlmapi.dll'
  442. go
  443.  
  444. dump tran master with truncate_only
  445. go
  446.  
  447. /* Script file to add extended stored procedures for NT integrated login
  448. ** security.
  449. */
  450.  
  451. sp_addextendedproc 'xp_loginconfig', 'xplogin.dll'
  452. go
  453. sp_addextendedproc 'xp_logininfo', 'xplogin.dll'
  454. go
  455. sp_addextendedproc 'xp_revokelogin', 'xplogin.dll'
  456. go
  457. sp_addextendedproc 'xp_grantlogin', 'xplogin.dll'
  458. go
  459.  
  460. create proc MS_sqlctrs_users
  461. as
  462. begin
  463. select distinct sysprocesses.spid, memusage 'Memory (2K Pages)', cpu 'CPU time',
  464.        physical_io,count(syslocks.spid) 'Locks held'
  465. from sysprocesses, syslocks where sysprocesses.spid *= syslocks.spid
  466. group by sysprocesses.spid
  467. end
  468. go
  469. grant execute on MS_sqlctrs_users to public
  470. go
  471.  
  472. execute sp_configure 'update', 0
  473. go
  474. reconfigure with override
  475. go
  476.  
  477. dump tran master with truncate_only
  478. go
  479.