home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0430 - 0439 / ibm0430-0439 / ibm0438.tar / ibm0438 / SQL42109.ZIP / SQL421A.009 / SQL / I386 / DNNT42.SQL < prev    next >
Encoding:
Text File  |  1994-07-14  |  11.6 KB  |  503 lines

  1. /********************************************************************
  2. ** This script file will downgrade SQL Server for Windows NT to
  3. ** SQL Server 4.2
  4. ********************************************************************/
  5.  
  6. use master
  7. go
  8.  
  9. /*
  10. ** Make sure we have enough space in master db to
  11. ** complete this script
  12. */
  13. dump tran master with truncate_only
  14. go
  15.  
  16. execute sp_configure 'update', 1
  17. go
  18.  
  19. reconfigure with override
  20. go
  21.  
  22. /*
  23. ** Drop NT specific error messages
  24. */
  25. delete from sysmessages where error between 4027 and 4034
  26.     or error in (114,227,423,1708,3609,5016,5017,7964,7965,7966)
  27. go
  28.  
  29. /*
  30. ** Delete rows where tape messages existed in Beta II version.
  31. */
  32. if charindex('Mar 22',@@version) <> 0
  33.   begin
  34.     delete from sysmessages where
  35.       error=4390 and description like "Mount first%"
  36.     delete from sysmessages where
  37.       error=4391 and description like "End of tape has%"
  38.     delete from sysmessages where
  39.       error=4392 and description like "Database '%"
  40.     delete from sysmessages where
  41.       error=4393 and description like "Tape '%"
  42.     delete from sysmessages where
  43.       error=4394 and description like "Creation date %"
  44.     delete from sysmessages where
  45.       error=4395 and description like "Cannot find file %"
  46.     delete from sysmessages where
  47.       error=4396 and description like "File <%"
  48.     delete from sysmessages where
  49.       error=4397 and description like "Warning, file <%"
  50.   end
  51. go
  52.  
  53. /*
  54. ** Remove sp_configure parameters for SQL Server/NT and spt_values
  55. **   and to sysconfigures
  56. */
  57. delete from sysconfigures where config between 501 and 503
  58. go
  59. delete from spt_values where name = 'tempdb in ram' and number = 501
  60. go
  61. delete from spt_values where name = 'max async IO' and number = 502
  62. go
  63. delete from spt_values where name = 'max worker threads' and number = 503
  64. go
  65.  
  66. dump tran master with truncate_only
  67. go
  68.  
  69. /* */
  70. /* Drop the NT specific procedures */
  71. /* */
  72. if exists ( select * from sysobjects
  73.         where sysstat & 7 = 4
  74.             and name = 'MS_sqlctrs_users' )
  75.     drop proc MS_sqlctrs_users
  76. go
  77.  
  78. if exists ( select * from sysobjects
  79.         where sysstat & 7 = 4
  80.             and name = 'MS_sqlctrs_locks' )
  81.     drop proc MS_sqlctrs_locks
  82. go
  83.  
  84. if exists (select * from sysobjects
  85.         where sysstat & 7 = 4
  86.             and name = 'xp_logininfo')
  87.     begin
  88.  
  89.     delete syscomments
  90.        from syscomments,sysobjects
  91.        where syscomments.id = sysobjects.id
  92.          and sysobjects.name = 'xp_logininfo'
  93.          and sysobjects.sysstat & 7 = 4
  94.  
  95.     delete from sysobjects
  96.        where sysobjects.name = 'xp_logininfo'
  97.          and sysobjects.sysstat & 7 = 4
  98.  
  99.     end
  100. go
  101.  
  102. if exists (select * from sysobjects
  103.         where sysstat & 7 = 4
  104.             and name = 'xp_loginconfig')
  105.     begin
  106.  
  107.     delete syscomments
  108.        from syscomments,sysobjects
  109.        where syscomments.id = sysobjects.id
  110.          and sysobjects.name = 'xp_loginconfig'
  111.          and sysobjects.sysstat & 7 = 4
  112.  
  113.     delete from sysobjects
  114.        where sysobjects.name = 'xp_loginconfig'
  115.          and sysobjects.sysstat & 7 = 4
  116.  
  117.     end
  118. go
  119.  
  120. if exists (select * from sysobjects
  121.         where sysstat & 7 = 4
  122.             and name = 'xp_grantlogin')
  123.     begin
  124.  
  125.     delete syscomments
  126.        from syscomments,sysobjects
  127.        where syscomments.id = sysobjects.id
  128.          and sysobjects.name = 'xp_grantlogin'
  129.          and sysobjects.sysstat & 7 = 4
  130.  
  131.     delete from sysobjects
  132.        where sysobjects.name = 'xp_grantlogin'
  133.          and sysobjects.sysstat & 7 = 4
  134.  
  135.     end
  136. go
  137.  
  138. if exists (select * from sysobjects
  139.         where sysstat & 7 = 4
  140.             and name = 'xp_revokelogin')
  141.     begin
  142.  
  143.     delete syscomments
  144.        from syscomments,sysobjects
  145.        where syscomments.id = sysobjects.id
  146.          and sysobjects.name = 'xp_revokelogin'
  147.          and sysobjects.sysstat & 7 = 4
  148.  
  149.     delete from sysobjects
  150.        where sysobjects.name = 'xp_revokelogin'
  151.          and sysobjects.sysstat & 7 = 4
  152.  
  153.     end
  154. go
  155.  
  156. if exists (select * from sysobjects
  157.         where sysstat & 7 = 4
  158.             and name = 'xp_cmdshell')
  159.     begin
  160.  
  161.     delete syscomments
  162.        from syscomments,sysobjects
  163.        where syscomments.id = sysobjects.id
  164.          and sysobjects.name = 'xp_cmdshell'
  165.          and sysobjects.sysstat & 7 = 4
  166.  
  167.     delete from sysobjects
  168.        where sysobjects.name = 'xp_cmdshell'
  169.          and sysobjects.sysstat & 7 = 4
  170.  
  171.     end
  172. go
  173.  
  174. if exists (select * from sysobjects
  175.         where sysstat & 7 = 4
  176.             and name = 'xp_logevent')
  177.     begin
  178.  
  179.     delete syscomments
  180.        from syscomments,sysobjects
  181.        where syscomments.id = sysobjects.id
  182.          and sysobjects.name = 'xp_logevent'
  183.          and sysobjects.sysstat & 7 = 4
  184.  
  185.     delete from sysobjects
  186.        where sysobjects.name = 'xp_logevent'
  187.          and sysobjects.sysstat & 7 = 4
  188.  
  189.     end
  190. go
  191.  
  192. if exists (select * from sysobjects
  193.         where sysstat & 7 = 4
  194.             and name = 'xp_enumgroups')
  195.     begin
  196.  
  197.     delete syscomments
  198.        from syscomments,sysobjects
  199.        where syscomments.id = sysobjects.id
  200.          and sysobjects.name = 'xp_enumgroups'
  201.          and sysobjects.sysstat & 7 = 4
  202.  
  203.     delete from sysobjects
  204.        where sysobjects.name = 'xp_enumgroups'
  205.          and sysobjects.sysstat & 7 = 4
  206.  
  207.     end
  208. go
  209.  
  210. dump tran master with truncate_only
  211. go
  212.  
  213. if exists (select *
  214.     from sysobjects
  215.         where sysstat & 7 = 4
  216.             and name = 'sp_addextendedproc')
  217. begin
  218.     drop procedure sp_addextendedproc
  219. end
  220. go
  221.  
  222. if exists (select *
  223.     from sysobjects
  224.         where sysstat & 7 = 4
  225.             and name = 'sp_dropextendedproc')
  226. begin
  227.     drop procedure sp_dropextendedproc
  228. end
  229. go
  230.  
  231. if exists (select *
  232.     from sysobjects
  233.         where sysstat & 7 = 4
  234.             and name = 'sp_helpextendedproc')
  235. begin
  236.     drop procedure sp_helpextendedproc
  237. end
  238. go
  239.  
  240. /*
  241. **  Drop NT specific version of sp_configure.
  242. */
  243. if exists (select *
  244.     from sysobjects
  245.         where sysstat & 7 = 4
  246.             and name = 'sp_configure')
  247. begin
  248.     drop procedure sp_configure
  249. end
  250. go
  251.  
  252. /* */
  253. /* Change the operating system version back to OS/2*/
  254. /* */
  255.  
  256. update spt_values set name = "OS/2"
  257. where name = "WINDOWS/NT"
  258. go
  259. update spt_values set high = 32000
  260. where name = "memory"
  261. go
  262.  
  263. /*
  264. ** Recreate OS/2 specific version of sp_configure.
  265. */
  266. create procedure sp_configure
  267. @configname varchar(20) = NULL,        /* option name to configure */
  268. @configvalue int = NULL            /* configure value */
  269. as
  270.  
  271. declare @confignum int            /* number of option to be configured */
  272. declare @configcount int        /* number of options like @configname */
  273.  
  274. /*
  275. **  If no option name is given, the procedure will just print out all the
  276. **  options and their values.
  277. */
  278. if @configname is NULL
  279. begin
  280.     select name, minimum = low, maximum = high,
  281.         config_value = sysconfigures.value,
  282.         run_value = syscurconfigs.value
  283.     from spt_values, sysconfigures, syscurconfigs
  284.         where type = "C"
  285.             and number *= sysconfigures.config
  286.             and number *= syscurconfigs.config
  287.             and number >= 0
  288.  
  289.     return (0)
  290. end
  291.  
  292. set nocount on
  293.  
  294. /*
  295. **  Use @configname and try to find the right option.
  296. **  If there isn't just one, print appropriate diagnostics and return.
  297. */
  298. select @configcount = count(*)
  299.         from spt_values
  300.         where name like "%" + @configname + "%" and type = "C"
  301.             and number >= 0
  302.  
  303. /*
  304. **  If no option, show the user what the options are.
  305. */
  306. if @configcount = 0
  307. begin
  308.     print "Configuration option doesn't exist."
  309.  
  310.     /*
  311.     ** Show the user what the options are.
  312.     */
  313.     select name, minimum = low, maximum = high,
  314.         config_value = sysconfigures.value,
  315.         run_value = syscurconfigs.value
  316.     from spt_values, sysconfigures, syscurconfigs
  317.         where type = "C"
  318.             and number *= sysconfigures.config
  319.             and number *= syscurconfigs.config
  320.             and number >= 0
  321.     return (0)
  322. end
  323.  
  324. /*
  325. **  If more than one option like @configname, show the duplicates and return.
  326. */
  327. if @configcount > 1
  328. begin
  329.     print "Configuration option is not unique."
  330.  
  331.     select duplicate_options = name
  332.         from spt_values
  333.             where name like "%" + @configname + "%"
  334.                 and type = "C"
  335.                 and number >= 0
  336.  
  337.     return (1)
  338. end
  339.  
  340. /*
  341. ** If @configvalue is NULL, just show the current state of the option.
  342. */
  343. if @configvalue = NULL
  344. begin
  345.     select name, minimum = low, maximum = high,
  346.         config_value = sysconfigures.value,
  347.         run_value = syscurconfigs.value
  348.     from spt_values, sysconfigures, syscurconfigs
  349.         where type = "C"
  350.             and number *= sysconfigures.config
  351.             and number *= syscurconfigs.config
  352.             and name like "%" + @configname + "%"
  353.             and number >= 0
  354.     return (0)
  355. end
  356.  
  357. /*
  358. **  Only the SA can execute the update part of this procedure so check.
  359. */
  360. if suser_id() != 1
  361. begin
  362.     print "Only the System Administrator (SA) may change configuration parameters."
  363.     return (1)
  364. end
  365.  
  366. /*
  367. **  Now get the configuration number.
  368. */
  369. select @confignum = number
  370.     from spt_values
  371.         where type = "C" and (@configvalue between low and high
  372.             or @configvalue = 0)
  373.             and name like "%" + @configname + "%"
  374.             and number >= 0
  375.  
  376.  
  377. /*
  378. **  If this is the number of devices configuration parameter,
  379. **  we want to make sure that it's not being set to lower than the
  380. **  number of devices in sysdevices.
  381. */
  382. if @confignum = 116
  383. begin
  384.     /*
  385.     **  Get the max vdevno.
  386.     */
  387.     declare @maxvdevno    int
  388.     select @maxvdevno = max(convert(tinyint, substring(convert(binary(4),
  389.         d.low), v.low, 1)))
  390.     from master.dbo.sysdevices d, master.dbo.spt_values v
  391.         where v.type = "E"
  392.         and v.number = 3
  393.  
  394.     /*
  395.     **  If @configvalue == 0, then set it to the current number of devices.
  396.     */
  397.     if @configvalue = 0
  398.     select @configvalue = @maxvdevno + 1
  399.     if (select low
  400.         from master.dbo.spt_values
  401.             where type = "C"
  402.                 and number = 116) > @configvalue
  403.     begin
  404.         select @configvalue = low
  405.             from master.dbo.spt_values
  406.                 where type = "C"
  407.                     and number = 116
  408.     end
  409.  
  410.     if ((@maxvdevno + 1) > @configvalue)
  411.     begin
  412.         print "You can't set the number of devices to be less than the number of devices already defined in sysdevices."
  413.         return (1)
  414.     end
  415. end
  416.  
  417. /*
  418. **  If this is the number of default language, we want to make sure
  419. **  that the new value is a valid language id in Syslanguages.
  420. */
  421. if @confignum = 124
  422. begin
  423.     if not exists (select *
  424.         from syslanguages
  425.             where langid = @configvalue)
  426.     begin
  427.         /* 0 is Sybase default language, us_english */
  428.         if @configvalue != 0
  429.         begin
  430.             print "You can't set the default language to a language ID that is not defined in Syslanguages."
  431.             return (1)
  432.         end
  433.     end
  434. end
  435.  
  436. /*
  437. **  If this is the number of kernel language, we want to make sure
  438. **  that the new value is a valid language id in Syslanguages.
  439. */
  440. if @confignum = 132
  441. begin
  442.     if not exists (select *
  443.         from syslanguages
  444.             where langid = @configvalue)
  445.     begin
  446.         /* 0 is Sybase default language, us_english */
  447.         if @configvalue != 0
  448.         begin
  449.             print "You can't set the kernel language to a language ID that is not defined in Syslanguages."
  450.             return (1)
  451.         end
  452.     end
  453. end
  454. /*
  455. **  Although the @configname is good, @configvalue wasn't in range.
  456. */
  457. if @confignum is NULL
  458. begin
  459.     print "Configuration option value is not legal."
  460.     return (1)
  461. end
  462.  
  463. /*
  464. **  If we're in a transaction, disallow this since it might make recovery
  465. **  impossible.
  466. */
  467. if @@trancount > 0
  468. begin
  469.     print "Can't run sp_configure from within a transaction."
  470.     return (1)
  471. end
  472.  
  473. /*
  474. **  Now update sysconfigure.
  475. */
  476. update sysconfigures
  477.     set value = @configvalue
  478.         where config = @confignum
  479.  
  480. print "Configuration option changed. Run the RECONFIGURE command to install."
  481.  
  482. return (0)
  483. go
  484. grant execute on sp_configure to public
  485. go
  486. dump transaction master with no_log
  487. go
  488.  
  489. /*
  490. ** Set max connections back to OS/2 value if necessary
  491. */
  492. if (select high from spt_values where name = 'user connections') > 256
  493.    update spt_values set high = 256 where name = 'user connections'
  494. go
  495.  
  496. execute sp_configure 'update', 0
  497. go
  498. reconfigure with override
  499. go
  500.  
  501. dump tran master with truncate_only
  502. go
  503.