1 /* Script generated by dbschema.pl(2.4.2) on Mon Aug 18 14:15:25 2003. */
2 /* Script extracted on a solaris system. */
14 exec sp_adduser 'guest', 'guest'
15 exec sp_adduser 'probe', 'probe'
20 /* No aliases found. */
22 /* Add user-defined data types: */
24 /* No user defined types found. */
33 /* No defaults found. */
34 /* Bind rules & defaults to user data types... */
36 /* No defaults to bind. */
38 /* No rules to bind. */
41 /* Start of description of table dbo.jdbc_function_escapes */
46 CREATE TABLE dbo.jdbc_function_escapes (
47 escape_name varchar(40) NOT NULL,
48 map_string varchar(40) NOT NULL
53 /* Add permissions for table... */
54 IF OBJECT_ID('dbo.jdbc_function_escapes') IS NOT NULL
56 GRANT SELECT ON dbo.jdbc_function_escapes TO public
60 /* Bind rules & defaults to columns... */
61 /* End of description of table dbo.jdbc_function_escapes */
64 /* Start of description of table dbo.spt_jdbc_conversion */
69 CREATE TABLE dbo.spt_jdbc_conversion (
70 datatype int NOT NULL,
71 conversion char(20) NOT NULL
76 /* Add permissions for table... */
77 IF OBJECT_ID('dbo.spt_jdbc_conversion') IS NOT NULL
79 GRANT SELECT ON dbo.spt_jdbc_conversion TO public
83 /* Bind rules & defaults to columns... */
84 /* End of description of table dbo.spt_jdbc_conversion */
87 /* Start of description of table dbo.spt_jdbc_table_types */
92 CREATE TABLE dbo.spt_jdbc_table_types (
93 TABLE_TYPE char(15) NOT NULL
98 /* Add permissions for table... */
99 IF OBJECT_ID('dbo.spt_jdbc_table_types') IS NOT NULL
101 GRANT SELECT ON dbo.spt_jdbc_table_types TO public
105 /* Bind rules & defaults to columns... */
106 /* End of description of table dbo.spt_jdbc_table_types */
109 /* Start of description of table dbo.spt_jtext */
114 CREATE TABLE dbo.spt_jtext (
115 mdinfo varchar(30) NOT NULL,
122 /* Add permissions for table... */
123 IF OBJECT_ID('dbo.spt_jtext') IS NOT NULL
125 GRANT SELECT ON dbo.spt_jtext TO public
129 /* Bind rules & defaults to columns... */
130 /* End of description of table dbo.spt_jtext */
133 /* Start of description of table dbo.spt_limit_types */
138 CREATE TABLE dbo.spt_limit_types (
139 name char(30) NOT NULL,
140 id smallint NOT NULL,
141 enforced tinyint NOT NULL,
142 object_type smallint NOT NULL,
143 scope smallint NOT NULL,
144 units char(60) NOT NULL
149 /* Add permissions for table... */
150 IF OBJECT_ID('dbo.spt_limit_types') IS NOT NULL
152 GRANT SELECT ON dbo.spt_limit_types TO public
156 /* Bind rules & defaults to columns... */
157 /* End of description of table dbo.spt_limit_types */
160 /* Start of description of table dbo.spt_mda */
165 CREATE TABLE dbo.spt_mda (
166 mdinfo varchar(30) NOT NULL,
167 querytype tinyint NOT NULL,
168 query varchar(255) NULL,
169 mdaver_start tinyint NOT NULL,
170 mdaver_end tinyint NOT NULL,
171 srvver_start int NOT NULL,
172 srvver_end int NOT NULL
177 IF OBJECT_ID('dbo.spt_mda') IS NOT NULL
179 CREATE UNIQUE NONCLUSTERED INDEX spt_mda_ind
180 ON spt_mda (mdinfo, mdaver_end, srvver_end)
185 /* Add permissions for table... */
186 IF OBJECT_ID('dbo.spt_mda') IS NOT NULL
188 GRANT SELECT ON dbo.spt_mda TO public
192 /* Bind rules & defaults to columns... */
193 /* End of description of table dbo.spt_mda */
196 /* Start of description of table dbo.spt_monitor */
201 CREATE TABLE dbo.spt_monitor (
202 lastrun datetime NOT NULL,
203 cpu_busy int NOT NULL,
204 io_busy int NOT NULL,
206 pack_received int NOT NULL,
207 pack_sent int NOT NULL,
208 connections int NOT NULL,
209 pack_errors int NOT NULL,
210 total_read int NOT NULL,
211 total_write int NOT NULL,
212 total_errors int NOT NULL
218 /* Add permissions for table... */
219 IF OBJECT_ID('dbo.spt_monitor') IS NOT NULL
221 GRANT SELECT ON dbo.spt_monitor TO public
225 /* Bind rules & defaults to columns... */
226 /* End of description of table dbo.spt_monitor */
229 /* Start of description of table dbo.spt_values */
234 CREATE TABLE dbo.spt_values (
235 name varchar(28) NULL,
237 type char(2) NOT NULL,
246 IF OBJECT_ID('dbo.spt_values') IS NOT NULL
248 CREATE CLUSTERED INDEX spt_valuesclust
249 ON spt_values (number, type)
254 /* Add permissions for table... */
255 IF OBJECT_ID('dbo.spt_values') IS NOT NULL
257 GRANT SELECT ON dbo.spt_values TO public
261 /* Bind rules & defaults to columns... */
262 /* End of description of table dbo.spt_values */
265 /* Start of description of table dbo.syblicenseslog */
270 CREATE TABLE dbo.syblicenseslog (
271 status smallint NOT NULL,
272 logdate datetime NOT NULL,
273 maxlicenses int NOT NULL
278 /* Add permissions for table... */
279 /* Bind rules & defaults to columns... */
280 /* End of description of table dbo.syblicenseslog */
283 /* Now create the key definitions ...*/
291 /* No views found. */
295 /* Procedure sp_configure, owner dbo */
300 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
301 /* 4.8 1.1 06/14/90 sproc/src/configure */
304 ** Messages for "sp_configure" 17410
305 ** Must use "langid" when referencing spt_values
307 ** 17260, "Can't run %1! from within a transaction."
308 ** 17410, "Configuration option doesn't exist."
309 ** 17411, "Configuration option is not unique."
310 ** 17413, "The value of the 'number of devices' must be greater than the highest VDEVNO, '%1!', defined in sysdevices."
311 ** 17414, "You can't set the default language to a language ID that is not defined in Syslanguages."
312 ** 17415, "Configuration option value is not legal."
313 ** 17418, "'%1!' is an invalid file command. The valid commands are 'verify', 'read', 'write', and 'restore'."
314 ** 17419, "Configuration option changed. The SQL Server need not be rebooted since the option is dynamic.
315 ** 18123, "Configuration option changed. The SQL Server must be rebooted before the change in effect since the option is static."
316 ** 18124, "No matching configuration options. Here is a listing of groups:"
317 ** 18125, "Must provide the parameter 'filename'."
318 ** 18133, "The character set, '%1!', is invalid since it is not defined in Syscharsets."
319 ** 18134, "The sortorder, '%1!', is invalid since it is not defined in Syscharsets."
320 ** 18549, "Invalid third argument supplied: '%1!'. Valid choices are
321 ** 'with truncate' or 'default'."
323 create procedure sp_configure
324 @configname varchar(80) = NULL, /* configure option name */
325 @configvalue int = NULL, /* configure value */
326 @configvalue2 varchar(255) = NULL, /* config file command/charset info */
327 @configvalue3 varchar(255) = NULL /* physical name of file */
330 declare @confignum int /* number of option to be configured */
331 declare @configcount int /* number of options like @configname */
332 declare @whichone int /* using english or default lang ? */
333 declare @cmd smallint /* configuration file command */
334 declare @status int /* return status for misc calls */
335 declare @children int /* number of children in a group */
336 declare @parent int /* config number of parent group */
337 declare @msg varchar(255) /* temp buffer for messages */
338 declare @sysconfig smallint /* contents of sysconfigures.config */
339 declare @sysname varchar(255) /* contents of sysconfigures.comment */
340 declare @sysparent smallint /* contents of sysconfigures.parent */
341 declare @sysstatus smallint /* contents of sysconfigures.status */
342 declare @value int /* default charset/sort order id */
343 declare @user_displaylevel int /* user display level */
344 declare @maxvdevno int /* highest number of vdevno */
345 declare @sortorder_id int /* current sortorder id */
346 declare @charset_id int /* current charset id */
347 declare @use_wildcard tinyint /* use wildcard to search option name or not */
348 declare @match_count int /* number of option found by name match */
349 declare @cache_part_temp int /* cache partition number */
350 declare @partition_number int /* cache partition number */
351 declare @cmpstate int /* Local NODE state in companionship */
352 declare @nocase tinyint /* case-sensitive sort order flag */
358 select @user_displaylevel = NULL
359 select @sortorder_id =
360 value from master.dbo.syscurconfigs where config = 123
362 value from master.dbo.syscurconfigs where config = 131
364 select @use_wildcard = 1
367 ** Check if the default sort order is case-insensitive.
375 ** Disallow running sp_configure within a transaction since it might make
376 ** recovery impossible.
381 ** 17260, "Can't run %1! from within a transaction."
383 raiserror 17260, "sp_configure"
391 set transaction isolation level 1
395 ** If the "default sortorder" is case insensitive dictionary sort order,
396 ** the procedure will just print out all the options and their values
397 ** without grouping if no option name is given.
399 if (@nocase = 1 and @configname is NULL)
401 select "Parameter Name" = convert(char(30), name),
402 "Default" = convert(char(11), space(11-char_length(
403 convert(varchar(11), defvalue)))+
404 convert(varchar(11), defvalue)),
405 "Memory Used" = convert(char(11), space(11-char_length(
406 convert(varchar(11), b.comment)))+
407 convert(varchar(11), b.comment)),
408 "Config Value" =convert(char(11), space(11-char_length(
409 isnull(a.value2, convert(char(32), a.value)))) +
410 isnull(a.value2, convert(char(32), a.value))),
411 "Run Value" = convert(char(11), space(11-char_length(
412 isnull(b.value2, convert(char(32), b.value)))) +
413 isnull(b.value2, convert(char(32), b.value)))
414 from master.dbo.sysconfigures a,
415 master.dbo.syscurconfigs b
425 /* Validate the configname if it not NULL */
426 if @configname is not NULL
428 select @configcount = count(*)
429 from master.dbo.sysconfigures
430 where name like "%" + @configname + "%"
434 ** If configure option is not unique and case-insensitive
435 ** dictionary sort order is used, check if unique option found
436 ** by exact name match, if so, then disable wildcard match
437 ** for searching option name.
439 if (@configcount > 1 and @nocase = 1)
441 /* check if unique option found by exact name match */
442 select @match_count = count(*)
443 from master.dbo.sysconfigures
444 where name = @configname
448 select @use_wildcard = 0 /* don't use wildcard */
449 select @configcount = @match_count
454 ** If more than one option like @configname,
455 ** show the duplicates and return.
460 ** 17411, "Configuration option is not unique."
465 select "Parameter Name" = convert(char(30), name),
466 "Default" = convert(char(11), space(11-char_length(
467 convert(varchar(11), defvalue)))+
468 convert(varchar(11), defvalue)),
469 "Memory Used" = convert(char(11), space(11-char_length(
470 convert(varchar(11), b.comment)))+
471 convert(varchar(11), b.comment)),
472 "Config Value" =convert(char(11), space(11-char_length(
473 isnull(a.value2, convert(char(32), a.value)))) +
474 isnull(a.value2, convert(char(32), a.value))),
475 "Run Value" = convert(char(11), space(11-char_length(
476 isnull(b.value2, convert(char(32), b.value)))) +
477 isnull(b.value2, convert(char(32), b.value)))
478 from master.dbo.sysconfigures a,
479 master.dbo.syscurconfigs b
482 and name like "%" + @configname + "%"
491 ** if it is a valid option and the @configvalue is not NULL,
494 if (@configcount != 0) and (@configvalue is not NULL)
497 select @confignum = config,
499 from master.dbo.sysconfigures
500 where name like "%" + @configname + "%"
505 ** If @configvalue2 is "default",
506 ** setting the value to default
508 if (@configvalue2 = "default")
514 ** If the option name is "configuration file"
519 ** if the file command is one of the valid
522 if ((@configvalue2 = "read") or
523 (@configvalue2 = "write") or
524 (@configvalue2 = "restore") or
525 (@configvalue2 = "verify"))
528 ** if filename is NULL
530 if (@configvalue3 is NULL)
532 /* 18125, "Must provide the parameter 'filename'." */
537 ** Must have sa_role to run these
540 if (proc_role("sa_role") < 1)
546 if (@configvalue2 = "verify")
549 if (@configvalue2 = "read")
552 if (@configvalue2 = "write")
555 if (@configvalue2 = "restore")
562 ** print the message to show the valid
565 raiserror 17418, @configvalue2
569 select @status = config_admin(@cmd,0,0,0,NULL,
584 /* get current default charset id */
585 select @value = value from
586 master.dbo.sysconfigures
589 if @configvalue2 is not NULL
591 /* validate the charset id */
592 if not exists (select *
593 from master..syscharsets
594 where name = @configvalue2
595 and type between 1000 and 1999)
598 /* 18133, "The character set, '%1!', is invalid since it
599 ** is not defined in Syscharsets."
601 raiserror 18133, @configvalue2
605 /* get default charset id from name */
607 from master..syscharsets
608 where name = @configvalue2
609 and type between 1000 and 1999
615 /* get current default sortord id */
616 select @value = value from
617 master.dbo.sysconfigures
620 if @configvalue2 is not NULL
622 /* validate the sortord id */
623 if not exists (select *
624 from master..syscharsets
625 where name = @configvalue2
626 and type between 2000 and 2999)
628 /* 18134, "The sortorder, '%1!', is invalid since it
629 ** is not defined in Syscharsets."
631 raiserror 18134, @configvalue2
635 /* get default sortorder id from name */
637 from master..syscharsets
638 where name = @configvalue2
639 and type between 2000 and 2999
644 ** If an attempt to enable a disk mirroring is made, and
645 ** if this happens to be a server with HA services turned
646 ** on, we disallow. Currently we do not support ASE HA
647 ** services along with sybase mirroring.
649 if (@confignum = 140 and @configvalue = 0)
651 select @cmpstate = @@cmpstate
654 /* 18816 Mirroring not allowed in ASE HA */
661 ** If an attempt to disable disk mirroring is being made,
662 ** ensure that there are no devices that are currently
666 if (@confignum = 140 and @configvalue = 1)
668 if (select count(*) from master.dbo.sysdevices
669 where status & 512 = 512) > 0
672 /* 18750, Unable to disable disk mirroring
673 ** because some devices are currently
674 ** mirrored. Use 'disk unmirror' to
675 ** unmirror these devices and then
676 ** re-run this sp_configure command.
685 ** If this is the number of devices configuration
686 ** parameter, we want to make sure that it's not being
687 ** set to lower than the
688 ** number of devices in sysdevices.
693 ** Get the default value if trying to set the
694 ** value to the default value
698 select @configvalue = convert(int, defvalue)
699 from master.dbo.syscurconfigs
704 ** Get the max vdevno.
706 select @maxvdevno = max(
708 substring(convert(binary(4), d.low),
710 from master.dbo.sysdevices d,
711 master.dbo.spt_values v
713 if (@configvalue <= @maxvdevno)
715 /* 17413, "The value of the 'number of devices' must be
716 ** greater than the highest VDEVNO, '%1!', defined
719 raiserror 17413, @maxvdevno
726 ** If this is the number of default language, we want
727 ** to make sure that the new value is a valid language
728 ** id in Syslanguages.
732 if not exists (select *
733 from master.dbo.syslanguages
734 where langid = @configvalue)
736 /* 0 is default language, us_english */
739 /* 17414, "You can't set the default language to a
740 ** language ID that is not defined in Syslanguages."
749 ** If this is the number of current audit table we want
750 ** to make sure that if "with truncate" opiton is not
751 ** provided new table is empty other wise fail.
755 if @configvalue2 is not NULL
757 if (@configvalue2 not in ("with truncate",
761 ** 18549, "Invalid third argument
762 ** supplied: '%1!'. Valid
763 ** choices are 'with truncate'
766 raiserror 18549, @configvalue2
778 if @configvalue is not NULL
780 if (@configvalue2 = "default")
782 select @partition_number = 1
786 select @partition_number =
790 if (@partition_number <= 0) OR
791 (@partition_number > 64)
797 select @cache_part_temp = 2
798 while @cache_part_temp < @partition_number
799 select @cache_part_temp =
801 if @partition_number != 1 AND
802 @cache_part_temp != @partition_number
810 /* call config_admin() to set the new value */
811 select @status = config_admin(@cmd, @confignum,
812 @configvalue, @value, NULL, @configvalue2)
817 /* Display the new value */
818 select "Parameter Name" = convert(char(30), name),
819 "Default" = convert(char(11), space(11-char_length(
820 convert(varchar(11), defvalue))) +
821 convert(varchar(11), defvalue)),
822 "Memory Used" = convert(char(11),space(11-char_length(
823 convert(varchar(11), c.comment))) +
824 convert(varchar(11), c.comment)),
825 "Config Value" = convert(char(11),
826 space(11-char_length(
827 isnull(b.value2, convert(char(32), b.value)))) +
828 isnull(b.value2, convert(char(32), b.value))),
829 "Run Value" = convert(char(11), space(11-char_length(
830 isnull(c.value2, convert(char(32), c.value)))) +
831 isnull(c.value2, convert(char(32), c.value)))
832 from master.dbo.sysconfigures b,
833 master.dbo.syscurconfigs c
835 b.config = @confignum and
839 ** print reboot message if this option is not
842 select @sysstatus = @sysstatus & 8
845 exec sp_getmessage 17419, @msg output
850 exec sp_getmessage 18123, @msg output
862 ** @configcount=0 implies @configname is not valid
863 ** @configname=NULL implies displaying all the parameters except for
864 ** the parameters with the config number equal to 19 or the parent equal
865 ** to 19 since those parameters are displayed by sp_cacheconfig.
869 /* 18124, "No matching configuration options.
870 ** Here is a listing of groups:"
873 select convert(char(50), name)
874 from master.dbo.sysconfigures
881 else if (@configname is NULL)
882 select @configname = "Config"
885 ** retrieve the display level from sysattributes
887 select @user_displaylevel = int_value from master.dbo.sysattributes where
890 object_type = 'L' AND
894 ** set the default display level to 10 if it is not defined in sysattributes
896 if (@user_displaylevel = NULL)
897 select @user_displaylevel = 10
900 ** If @use_wildcard = 0 and the default sortorder is case-insensitive
901 ** dictionary sort order, use exact match: name = @configname to get row,
902 ** otherwise use wildcard match: name like "%" + @configname + "%".
905 if (@use_wildcard = 0 and @nocase = 1)
907 select @confignum = config,
911 from master.dbo.sysconfigures
912 where name = @configname
917 select @confignum = config,
921 from master.dbo.sysconfigures
922 where name like "%" + @configname + "%"
926 select @children = count(*)
927 from master.dbo.sysconfigures
928 where parent = @confignum
932 /* @@nestlevel is problem area if a sproc calls sp_configure */
933 /* could pass in another param when recursing */
936 /* reached a leaf, notify parent */
941 /* display the information of the config parameter */
942 select "Parameter Name" = convert(char(30), name),
943 "Default" = convert(char(11), space(11-char_length(
944 convert(varchar(11), defvalue))) +
945 convert(varchar(11), defvalue)),
946 "Memory Used" = convert(char(11), space(11-char_length(
947 convert(varchar(11), c.comment))) +
948 convert(varchar(11), c.comment)),
949 "Config Value" = convert(char(11), space(11-char_length(
950 isnull(b.value2, convert(char(32), b.value)))) +
951 isnull(b.value2, convert(char(32), b.value))),
952 "Run Value" = convert(char(11), space(11-char_length(
953 isnull(c.value2, convert(char(32), c.value)))) +
954 isnull(c.value2, convert(char(32), c.value)))
955 from master.dbo.sysconfigures b,
956 master.dbo.syscurconfigs c
959 and name like "%" + @configname + "%"
967 select @msg = "Group: " + @sysname
972 /* this poor guy has kids, so recurse to leaves */
973 declare config_curs cursor for
974 select config, name, parent
975 from master.dbo.sysconfigures
976 where parent = @parent
981 fetch config_curs into @sysconfig, @sysname, @sysparent
983 while (@@sqlstatus = 0)
986 execute @status = sp_configure @sysname
992 ** this guy has leaves as kids,
993 ** so print out the leaves with
994 ** display level <= @user_displaylevel
995 ** Note: If a config parameter has more than one
996 ** parent, the extra parents are stored in
999 create table #configure_temp (config int)
1001 insert into #configure_temp
1003 from master.dbo.sysconfigures a,
1004 master.dbo.syscurconfigs b
1006 display_level <= @user_displaylevel
1007 and parent = @parent
1009 and a.config = b.config
1012 from master.dbo.syscurconfigs,
1013 master.dbo.sysattributes
1015 display_level <= @user_displaylevel
1018 and object_type = 'CP'
1019 and int_value = @parent
1023 if exists (select * from #configure_temp)
1025 select "Parameter Name" = convert(char(30), name),
1026 "Default" = convert(char(11), space(11-char_length(
1027 convert(varchar(11), defvalue))) +
1028 convert(varchar(11), defvalue)),
1029 "Memory Used" = convert(char(11), space(11-char_length(
1030 convert(varchar(11), c.comment))) +
1031 convert(varchar(11), c.comment)),
1032 "Config Value" = convert(char(11),space(11-char_length(
1033 isnull(b.value2, convert(char(32), b.value)))) +
1034 isnull(b.value2, convert(char(32), b.value))),
1035 "Run Value" = convert(char(11), space(11-char_length(
1036 isnull(c.value2, convert(char(32), c.value)))) +
1037 isnull(c.value2, convert(char(32), c.value)))
1038 from master.dbo.sysconfigures b,
1039 master.dbo.syscurconfigs c
1041 (select config from #configure_temp)
1042 and b.config = c.config
1046 drop table #configure_temp
1049 deallocate cursor config_curs
1056 ** this lucky guy has grandkids, so, continue
1058 fetch config_curs into
1059 @sysconfig, @sysname, @sysparent
1065 deallocate cursor config_curs
1071 IF OBJECT_ID('dbo.sp_configure') IS NOT NULL
1073 GRANT EXECUTE ON dbo.sp_configure TO public
1076 /* Procedure sp_dboption, owner dbo */
1081 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
1082 /* 4.8 1.1 06/14/90 sproc/src/a_values */
1085 ** Messages for "sp_dboption" 17420
1086 ** Use "langid" when looking at spt_values ???
1088 ** 17260, "Can't run %1! from within a transaction."
1089 ** 17420, "Settable database options."
1090 ** 17421, "No such database -- run sp_helpdb to list databases."
1091 ** 17422, "The 'master' database's options can not be changed."
1092 ** 17423, "Usage: sp_dboption [dbname, optname, {true | false}]"
1093 ** 17424, "Database option doesn't exist or can't be set by user."
1094 ** 17425, "Run sp_dboption with no parameters to see options."
1095 ** 17426, "Database option is not unique."
1096 ** 17428, "You must be in the 'master' database in order to change
1097 ** database options."
1098 ** 17429, "The database is currently in use -- 'read only' option
1100 ** 17430, "Run the CHECKPOINT command in the database that was changed."
1103 ** 17433, "Database option '%1!' turned ON for database '%2!'."
1104 ** 17434, "Database option '%1!' turned OFF for database '%2!'."
1105 ** 17289, "Set your curwrite to the hurdle of current database."
1106 ** 17436, "The 'single user' option is not valid for the 'tempdb'
1108 ** 17439, "You cannot turn on ''%1!' for '%2!' because it is an HA server
1109 ** that has been configured with the proxy_db option."
1112 create procedure sp_dboption
1113 @dbname varchar(30) = NULL, /* database name to change */
1114 @optname varchar(20) = NULL, /* option name to turn on/off */
1115 @optvalue varchar(10) = NULL /* true or false */
1118 declare @dbid int /* dbid of the database */
1119 declare @dbuid int /* id of the owner of the database */
1120 declare @statvalue smallint, /* number of option */
1121 @stattype char(2), /* status field flag */
1122 @statopt smallint, /* option mask, part 1 */
1123 @stat2opt smallint /* option mask, part 2 */
1124 declare @optcount int /* number of options like @optname */
1125 declare @success_msg varchar(255) /* success status message */
1126 declare @msg varchar(250)
1127 declare @sptlang int
1128 declare @true varchar(10)
1129 declare @false varchar(10)
1130 declare @whichone int /* which language? */
1131 declare @name varchar(30)
1132 declare @optmsgnum int /* identify one msgnum to compare */
1133 declare @msgcnt int /* count distinct dups */
1142 set transaction isolation level 1
1144 select @sptlang = @@langid, @whichone = 0
1149 select * from master.dbo.sysmessages where error
1150 between 17050 and 17069
1151 and langid = @@langid)
1157 ** If no @dbname given, just list the possible dboptions.
1158 ** Only certain status bits may be set or cleared.
1159 ** settable not settable
1160 ** ------------------------------ --------------------------
1161 ** allow select into/bulkcopy (4) don't recover (32)
1162 ** read only (1024) not recovered (256)
1163 ** dbo use only (2048) dbname has changed (16384)
1164 ** single user (4096)
1165 ** truncate log on checkpoint (8)
1166 ** no checkpoint on recovery (16)
1167 ** allow null (8192)
1168 ** ddl in tran (512)
1169 ** ALL SETTABLE OPTIONS (15900)
1170 ** abort xact on log full (1, type='D2')
1171 ** no space accounting (2, type='D2')
1172 ** auto identity(4, type='D2')
1173 ** identity in nonunique index(8, type='D2')
1174 ** auto identity unique index(64, type='D2')
1178 ** Look for the "settable options" mask in spt_values
1180 select @statopt = number
1181 from master.dbo.spt_values
1183 and name = "ALL SETTABLE OPTIONS"
1185 select @stat2opt = number
1186 from master.dbo.spt_values
1188 and name = "ALL SETTABLE OPTIONS"
1191 ** If we can't find the option masks, guess at them
1194 select @statopt = 4 | 8 | 16 | 512 | 1024 | 2048 | 4096 | 8192
1195 if @stat2opt is null
1196 select @stat2opt = 1 | 2 | 4 | 8 | 64
1201 ** 17420, "Settable database options."
1203 exec sp_getmessage 17420, @msg output
1207 select database_options = name
1208 from master.dbo.spt_values
1210 and number & @statopt = number
1211 and number & @statopt != @statopt)
1213 and number & @stat2opt = number
1214 and number & @stat2opt != @stat2opt))
1217 select database_options = name, convert(char(22), description)
1218 from master.dbo.spt_values, master.dbo.sysmessages
1220 and number & @statopt = number
1221 and number & @statopt != @statopt)
1223 and number & @stat2opt = number
1224 and number & @stat2opt != @stat2opt))
1226 and langid = @sptlang
1232 ** Verify the database name and get the @dbid and @dbuid
1234 select @dbid = dbid, @dbuid = suid
1235 from master.dbo.sysdatabases
1236 where name = @dbname
1239 ** If @dbname not found, say so and list the databases.
1244 ** 17421, "No such database -- run sp_helpdb to list databases."
1251 ** Only the Database Owner (DBO) or
1252 ** Accounts with SA role can execute it.
1253 ** Call proc_role() with the required SA role.
1255 if ((suser_id() != @dbuid) and (proc_role("sa_role") < 1))
1259 ** You can not change any of the options in master. If the user tries to
1260 ** do so tell them they can't.
1265 ** 17422, "The 'master' database's options can not be changed."
1272 ** Check remaining parameters.
1275 exec sp_getmessage 17431, @true out
1276 /* 17432, "false" */
1277 exec sp_getmessage 17432, @false out
1278 if @optname is NULL or lower(@optvalue) not in
1279 ("true", "false", @true, @false) or @optvalue is null
1282 ** 17423, "Usage: sp_dboption [dbname, optname, {true | false}]"
1289 ** Use @optname and try to find the right option.
1290 ** If there isn't just one, print appropriate diagnostics and return.
1292 select @optcount = count(*)
1293 from master.dbo.spt_values
1294 where name like "%" + @optname + "%"
1296 and number & @statopt = number)
1298 and number & @stat2opt = number))
1300 ** If more than one option like @optname, make sure they are not the same
1301 ** option ("trunc" and "trunc.", for example)
1305 select @optmsgnum = msgnum
1306 from master.dbo.spt_values
1307 where name like "%" + @optname + "%"
1309 and number & @statopt = number)
1311 and number & @stat2opt = number))
1313 select @msgcnt = count(msgnum)
1314 from master.dbo.spt_values
1315 where name like "%" + @optname + "%"
1317 and number & @statopt = number)
1319 and number & @stat2opt = number))
1320 and msgnum != @optmsgnum
1323 ** msgcnt of 0 indicates we really have just 1 unique dboption,
1324 ** probably due to alternate spelling.
1327 select @optcount = 1
1330 ** If no option, and alternate language is set, use other language
1332 if @optcount = 0 and @sptlang != 0
1334 select @optcount = count(*)
1335 from master.dbo.spt_values, master.dbo.sysmessages
1336 where description like "%" + @optname + "%"
1338 and number & @statopt = number)
1340 and number & @stat2opt = number))
1342 and langid = @sptlang
1343 select @whichone = 1
1345 ** If more than one option like @optname, make sure they are not the same
1346 ** option ("trunc" and "trunc.", for example)
1350 select @optmsgnum = msgnum
1351 from master.dbo.spt_values, master.dbo.sysmessages
1352 where description like "%" + @optname + "%"
1354 and number & @statopt = number)
1356 and number & @stat2opt = number))
1358 and langid = @sptlang
1360 select @msgcnt = count(msgnum)
1361 from master.dbo.spt_values, master.dbo.sysmessages
1362 where description like "%" + @optname + "%"
1364 and number & @statopt = number)
1366 and number & @stat2opt = number))
1368 and langid = @sptlang
1369 and msgnum != @optmsgnum
1372 ** msgcnt of 0 indicates we really have just 1 unique dboption,
1373 ** probably due to alternate spelling.
1376 select @optcount = 1
1381 ** If no option, show the user what the options are.
1386 ** 17424, "Database option doesn't exist or can't be set by user."
1391 ** 17425, "Run sp_dboption with no parameters to see options."
1393 exec sp_getmessage 17425, @msg output
1399 ** If more than one option like @optname, show the duplicates and return.
1404 ** 17426, "Database option is not unique."
1409 select duplicate_options = name
1410 from master.dbo.spt_values
1411 where name like "%" + @optname + "%"
1413 and number & @statopt = number)
1415 and number & @stat2opt = number))
1417 select duplicate_options = name, convert(char(22), description)
1418 from master.dbo.spt_values, master.dbo.sysmessages
1419 where (name like "%" + @optname + "%"
1420 or description like "%" + @optname + "%")
1422 and number & @statopt = number)
1424 and number & @stat2opt = number))
1426 and langid = @sptlang
1432 if db_name() != "master"
1435 ** 17428, "You must be in the 'master' database in order to change database options."
1442 ** User cannot set "tempdb" database in single user mode.
1444 select @statvalue = number
1445 from master.dbo.spt_values
1446 where name like "%" + @optname + "%"
1448 and number & @statopt = number)
1450 and number & @stat2opt = number))
1452 if (@dbid = 2) and (@statvalue = 4096)
1455 ** 17436, "The 'single user' option is not valid for the 'tempdb'
1463 ** If we're in a transaction, disallow this since it might make recovery
1469 ** 17260, "Can't run %1! from within a transaction."
1471 raiserror 17260, "sp_dboption"
1479 set transaction isolation level 1
1482 ** Get the number which is the bit value to set
1485 select @statvalue = number, @stattype = type, @success_msg = name
1486 from master.dbo.spt_values
1487 where name like "%" + @optname + "%"
1489 and number & @statopt = number)
1491 and number & @stat2opt = number))
1493 select @statvalue = number, @stattype = type, @success_msg = name
1494 from master.dbo.spt_values, master.dbo.sysmessages
1495 where description like "%" + @optname + "%"
1497 and number & @statopt = number)
1499 and number & @stat2opt = number))
1501 and langid = @sptlang
1504 ** We do not allow 'sybsecurity' to be set to 'single user' since,
1505 ** if auditing is enabled and we try to set 'sybsecurity' database to
1506 ** 'single user' then, the audit process is killed because audit process
1507 ** tries to do 'usedb' and it fails (look at utils/auditing.c).
1509 if (@dbname = "sybsecurity") and (@statvalue = 4096)
1512 ** 17435, "The 'single user' option is not valid for the
1513 ** 'sybsecurity' database.
1521 ** Now update sysdatabases.
1524 if lower(@optvalue) in ("true", @true)
1527 ** If this the option to make the database read only,
1528 ** we need to do some checking first.
1529 ** Unless it's the master db, no one can be using it.
1530 ** If it's the master db, only the SA may be using it.
1532 if (@statvalue = 1024) and (select count(*)
1533 from master.dbo.sysprocesses
1534 where dbid = @dbid) > 0
1537 ** 17429, "The database is currently in use -- 'read only' option disallowed."
1544 ** If this is the option to set 'abort tran on log full' to
1545 ** true for sybsecurit database, then don't allow.
1547 if (db_name(@dbid) = "sybsecurity"
1548 and @stattype = "D2" and @statvalue = 1)
1551 ** AUDIT_CHANGE: New error message needs to be reserved and
1552 ** the print statement needs to be removed.
1554 print "You cannot set 'abort tran on log full' to true for sybsecurity database."
1559 ** Disallow DDL IN TRAN
1560 ** if proxydb option is set (@@crthaproxy = 1)
1561 ** if this server is a HA server (@@cmpstate >= 0)
1563 if ((@statvalue = 512) and (@@crthaproxy = 1) and (@@cmpstate >= 0))
1566 ** Cannot set DDL_IN_TRAN option for HA servers
1567 ** configured with proxy_db option.
1569 select @name = db_name(@dbid)
1570 exec sp_getmessage 17439, @msg output
1571 print @msg, @success_msg, @name
1575 if (@stattype = "D")
1576 update master.dbo.sysdatabases
1577 set status = status | @statvalue
1580 update master.dbo.sysdatabases
1581 set status2 = status2 | @statvalue
1584 ** 17433, "Database option %1! turned ON for database %2!."
1586 exec sp_getmessage 17433, @msg output
1587 select @name = db_name(@dbid)
1588 print @msg, @success_msg, @name
1592 ** We want to turn it off.
1597 if (@stattype = "D")
1598 update master.dbo.sysdatabases
1599 set status = status & ~@statvalue
1602 update master.dbo.sysdatabases
1603 set status2 = status2 & ~@statvalue
1606 ** 17434, "Database option %1! turned OFF for database %2!."
1608 exec sp_getmessage 17434, @msg output
1609 select @name = db_name(@dbid)
1610 print @msg, @success_msg, @name
1614 ** Advise the user to run the CHECKPOINT command in the database that
1618 ** 17430, "Run the CHECKPOINT command in the database that was changed."
1620 exec sp_getmessage 17430, @msg output
1627 IF OBJECT_ID('dbo.sp_dboption') IS NOT NULL
1629 GRANT EXECUTE ON dbo.sp_dboption TO public
1632 /* Procedure sp_dbupgrade, owner dbo */
1637 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
1640 create procedure sp_dbupgrade
1648 set transaction isolation level 1
1651 ** Do the sysindexes column names update which is part of the 38 upgrade.
1652 ** The sysgams updates have already been taken care of by pg_gamalloc.
1654 print "Upgrading Sysindexes columns in the database"
1655 if not exists (select name from syscolumns where id = 2 and name = 'doampg')
1659 where id = 2 and name = 'dpages'
1662 where id = 2 and name = 'reserved'
1665 where id = 2 and name = 'used'
1668 where id = 2 and name = 'rows'
1671 /* The following updates are part of the 42 upgrade. */
1674 ** Tweak the Syscolumns entries for the Sysindexes table so that
1675 ** "soid" and "csid" replace half of "usagecnt".
1677 if not exists (select * from syscolumns where id = 2 and name = 'soid')
1681 set type = 52, length = 2, usertype = 6, offset = 42
1682 where id = 2 and colid = 13
1683 insert into syscolumns
1684 (id, number, colid, status, type, length, offset,
1685 usertype, cdefault, domain, name, printfmt)
1686 values (2, 0, 23, 0, 48, 1, 40, 5, 0, 0, 'soid', '')
1687 insert into syscolumns
1688 (id, number, colid, status, type, length, offset,
1689 usertype, cdefault, domain, name, printfmt)
1690 values (2, 0, 24, 0, 48, 1, 41, 5, 0, 0, 'csid', '')
1694 print "Adding new datatypes to the database."
1695 if exists (select * from systypes where name = 'text')
1697 delete systypes where name = 'text'
1699 insert systypes (uid, usertype, variable, allownulls, type, length,
1700 tdefault, domain, name, printfmt)
1701 values (1, 19, 0, 1, 35, 16, 0, 0, 'text', null)
1702 if exists (select * from systypes where name = 'image')
1704 delete systypes where name = 'image'
1706 insert systypes (uid, usertype, variable, allownulls, type, length,
1707 tdefault, domain, name, printfmt)
1708 values (1, 20, 0, 1, 34, 16, 0, 0, 'image', null)
1709 if exists (select * from systypes where name = 'timestamp')
1711 delete systypes where name = 'timestamp'
1713 insert systypes (uid, usertype, variable, allownulls, type, length,
1714 tdefault, domain, name, printfmt)
1715 values (1, 80, 0, 1, 37, 8, 0, 0, 'timestamp', null)
1716 if exists (select * from systypes where name = 'smallmoney')
1718 delete systypes where name = 'smallmoney'
1720 insert systypes (uid, usertype, variable, allownulls, type, length,
1721 tdefault, domain, name, printfmt)
1722 values (1, 21, 0, 1, 122, 4, 0, 0, 'smallmoney', null)
1723 if exists (select * from systypes where name = 'smalldatetime')
1725 delete systypes where name = 'smalldatetime'
1727 insert systypes (uid, usertype, variable, allownulls, type, length,
1728 tdefault, domain, name, printfmt)
1729 values (1, 22, 0, 1, 58, 4, 0, 0, 'smalldatetime', null)
1730 if exists (select * from systypes where name = 'real')
1732 delete systypes where name = 'real'
1734 insert systypes (uid, usertype, variable, allownulls, type, length,
1735 tdefault, domain, name, printfmt)
1736 values (1, 23, 0, 1, 59, 4, 0, 0, 'real', null)
1738 /* 4.9 user types for national character */
1739 if exists (select * from systypes where name = 'nchar')
1741 delete systypes where name = 'nchar'
1743 insert systypes (uid, usertype, variable, allownulls, type, length,
1744 tdefault, domain, name, printfmt )
1745 values (1, 24, 0, 1, 47, 255, 0, 0, 'nchar', null)
1747 if exists (select * from systypes where name = 'nvarchar')
1749 delete systypes where name = 'nvarchar'
1751 insert systypes (uid, usertype, variable, allownulls, type, length,
1752 tdefault, domain, name, printfmt)
1753 values (1, 25, 1, 1, 39, 255, 0, 0, 'nvarchar', null)
1755 if exists (select * from systypes where name = 'NULL')
1757 delete systypes where name = 'NULL'
1759 insert systypes (uid, usertype, variable, allownulls, type, length,
1760 tdefault, domain, name, printfmt)
1761 values (1, 0, 0, 1, 0, 0, 0, 0, 'NULL', null)
1763 /* 4.9 system table creation */
1764 print "Creating system catalog: sysusermessages and its indexes."
1765 if not exists (select * from sysobjects where name='sysusermessages')
1767 execute sp_configure 'allow updates', 1
1768 reconfigure with override
1772 create table sysusermessages(error int,uid smallint,
1773 description varchar(255), langid smallint null) lock allpages
1774 create clustered index csysusermessages
1775 on sysusermessages (error)
1776 create unique nonclustered index ncsysusermessages
1777 on sysusermessages (error, langid)
1781 execute sp_configure 'allow updates', 0
1782 reconfigure with override
1785 print "Shutting down SQL Server"
1792 /* Procedure sp_getmessage, owner dbo */
1798 /* generic/sproc/getmessage 14.2 4/25/91 */
1800 /* Messages from sysmessages
1801 ** 17200, "Message number must be greater than or equal to 17000."
1802 ** 17201, "'%1!' is not an official language name from Syslanguages."
1803 ** 17202, "Message number %1! does not exist in the %2! language."
1806 create procedure sp_getmessage
1808 @result varchar(255) output,
1809 @language varchar(30) = NULL
1812 declare @lang_id smallint
1813 declare @msg varchar(255)
1814 declare @returncode smallint
1821 set transaction isolation level 1
1824 ** Use default language if none specified,
1825 ** and initialize result
1827 select @lang_id = @@langid, @result = NULL
1829 /* Only retrieve external errors */
1830 if @message_num < 17000
1832 /* 17200 "Message number must be greater than or equal to 17000." */
1833 select @msg = description from master.dbo.sysmessages
1840 ** Check that language is valid.
1842 if @language is not NULL
1844 execute @returncode = sp_validlang @language
1847 /* Us_english is always valid */
1848 if @language != "us_english"
1851 ** 17201, "'%1!' is not an official language
1852 ** name from Syslanguages."
1854 select @msg = description from master.dbo.sysmessages
1856 and langid = @@langid
1858 /* Get english if the current language is missing */
1860 select @msg = description from master.dbo.sysmessages
1864 print @msg, @language
1868 /* set to us_english */
1869 select @lang_id = NULL
1873 select @lang_id = langid from master.dbo.syslanguages
1874 where @language = name
1878 /* The langid is assigned 0 since it gets its value from @@langid. */
1879 /* For us_english, we have to insert it as NULL and not 0, this is */
1880 /* to maintain compatibility with the current conventions */
1883 select @lang_id = NULL
1886 /* Get message from the proper place */
1887 /* System messages */
1888 if @message_num < 20000
1890 select @result = description from master.dbo.sysmessages
1891 where langid = @lang_id
1892 and error = @message_num
1894 /* Get english if the current language is missing */
1896 select @result = description from master.dbo.sysmessages
1897 where error = @message_num
1898 and (langid is NULL or langid =0)
1903 /* There is no proper alternate language for user messages */
1904 select @result = description from sysusermessages
1905 where langid = @lang_id
1906 and error = @message_num
1908 /* this is in here for compatibility with older revs which */
1909 /* by mistake used to add langid as 0 in sysusermessages */
1910 if @result is null and @lang_id is NULL
1911 select @result = description from sysusermessages
1912 where (langid = 0 or langid is NULL)
1913 and error = @message_num
1917 /* Warn the user if the message can't be found */
1920 /* 17202, "Message number %1! does not exist in the %2! language." */
1921 select @msg = description from master.dbo.sysmessages
1923 and langid = @@langid
1925 if @language is null
1926 select @language = @@language
1929 select @msg = "Message number %1! does not exist in the %2! language."
1931 print @msg, @message_num, @language
1940 IF OBJECT_ID('dbo.sp_getmessage') IS NOT NULL
1942 GRANT EXECUTE ON dbo.sp_getmessage TO public
1945 /* Procedure sp_loaddbupgrade, owner dbo */
1950 /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
1952 create procedure sp_loaddbupgrade
1953 @databasename varchar(30),
1954 @devname varchar(30)
1963 set transaction isolation level 1
1967 /* The recovery which is part of load database will perform the upgrade */
1968 load database @databasename from @devname
1976 /* Procedure sp_procxmode, owner dbo */
1981 /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
1984 ** 17756, "The execution of the stored procedure '%1!' in database
1985 ** '%2!' was aborted because there was an error in writing the
1986 ** replication log record."
1989 create procedure sp_procxmode
1990 @procname varchar(255) = null,
1991 @tranmode varchar(30) = null
1994 declare @uid smallint
1996 declare @msg varchar(250) /* message text */
1997 declare @dbname varchar(30)
2004 set transaction isolation level 1
2006 /* If either parameter is null we will be joining with a temporary table
2007 ** to convert transaction mode numbers (0, 1, 2) to strings ("Unchained",
2008 ** "Chained", "Any Mode").
2010 if ((@procname is null) or (@tranmode is null))
2012 create table #tranmode (intval integer, charval varchar(15))
2013 insert into #tranmode values(0, "Unchained")
2014 insert into #tranmode values(1, "Chained")
2015 insert into #tranmode values(2, "Any Mode")
2018 /* If the first parameter is null, we're to report the transaction-modes
2019 ** of every stored procedure in the current database.
2021 if (@procname is null)
2023 select "procedure name" = o.name, "user name" = user_name(o.uid),
2024 "transaction mode" = t.charval
2025 from sysobjects o, #tranmode t
2026 where ((o.type = "P") or (o.type = "XP")) and (t.intval = ((o.sysstat2 / 16) & 3))
2032 /* If only the second parameter is null, we're to report the
2033 ** transaction-mode of the specified stored procedure.
2035 if ((@procname is not null) and (@tranmode is null))
2037 if (not exists (select name from sysobjects
2038 where ((type = "P") or (type = "XP")) and
2039 (name = @procname)))
2042 ** Force an error message, since we haven't
2043 ** installed sp_getmessage yet.
2045 dbcc update_tmode(@procname, "Chained")
2048 select "procedure name" = o.name, "user name" = user_name(o.uid),
2049 "transaction mode" = t.charval
2050 from sysobjects o, #tranmode t
2051 where ((o.type = "P") or (o.type = "XP")) and (@procname = o.name) and
2052 (t.intval = ((o.sysstat2 / 16) & 3))
2057 /* If neither parameter is null, we're to set the transaction-mode
2058 ** of the specified procedure to the specified value.
2060 if ((@procname is not null) and (@tranmode is not null))
2062 /* Start the transaction to log the execution of this procedure.
2064 ** IMPORTANT: The name "rs_logexec is significant and is used by
2065 ** Replication Server
2067 begin transaction rs_logexec
2070 ** Update transaction-mode in both sysobjects and DES.
2072 dbcc update_tmode(@procname, @tranmode)
2074 /* If dbcc update_tmode returned an error, return
2079 rollback transaction rs_logexec
2084 ** Write the log record to replicate this invocation
2085 ** of the stored procedure.
2090 ** 17756, "The execution of the stored procedure '%1!'
2091 ** in database '%2!' was aborted because there
2092 ** was an error in writing the replication log
2095 select @dbname = db_name()
2096 raiserror 17756, "sp_procxmode", @dbname
2098 rollback transaction rs_logexec
2108 IF OBJECT_ID('dbo.sp_procxmode') IS NOT NULL
2110 GRANT EXECUTE ON dbo.sp_procxmode TO public
2113 /* Procedure sp_prtsybsysmsgs, owner dbo */
2118 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
2121 ** This procedure is needed to extract messages for the batch that creates
2122 ** the sybsystemprocs database. When return parameters are used in an execute
2123 ** statement that is a part of a SQL batch, the return values are printed
2124 ** with a heading before subsequent statements in the batch are executed.
2125 ** These headings could be confusing to a user that is looking at the results
2126 ** of the batch. Hence we print the message in a stored procedure
2129 create procedure sp_prtsybsysmsgs
2130 @i int, @size int = NULL, @size2 int = NULL
2133 declare @msg varchar(250)
2135 exec sp_getmessage @i, @msg out
2136 print @msg, @size, @size2
2140 /* Procedure sp_validlang, owner dbo */
2145 /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
2146 /* 4.8 1.1 06/14/90 sproc/src/serveroption */
2147 create procedure sp_validlang
2157 set transaction isolation level 1
2159 /* Check to see if this language is in Syslanguages. */
2161 from master.dbo.syslanguages
2170 IF OBJECT_ID('dbo.sp_validlang') IS NOT NULL
2172 GRANT EXECUTE ON dbo.sp_validlang TO public
2178 /* No triggers found. */