DatabaseProcApplicationCreatedLinks
sybsystemprocssp_helpdb  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/help */
4     /*
5     ** Messages for "sp_helpdb"             17590
6     **
7     ** 17111, "log only"
8     ** 17590, "The specified database does not exist."
9     ** 17591, "no options set"
10    ** 17592, " -- unused by any segments --"
11    ** 17714, "not applicable"
12    ** 17600, "sp_helpdb: order value '%1!' is not valid. Valid values are 
13    **	'lstart' and 'device_name'. Using default value 'lstart'."
14    ** 17609, "Device allocation is not displayed for local temporary 
15    **	   database '%1!'. To display this information, execute the 
16    **	   procedure on the owner instance '%2!'."
17    ** 17909, "log only unavailable". 
18    */
19    create procedure sp_helpdb
20        @dbname varchar(255) = NULL, /* database name to change */
21        @order varchar(20) = 'lstart' /* Use 'device_name' to order
22    						** by device name
23    						*/
24    as
25    
26        declare @showdev int,
27            @showinstance int,
28            @allopts int,
29            @all2opts int,
30            @all3opts int,
31            @all4opts int,
32            @dbstatus4 int,
33            @thisopt int,
34            @optmask int,
35            @optmax int,
36            @template_mask int,
37            @imdb_mask int,
38            @pgcomp_mask int,
39            @rowcomp_mask int,
40            @has_template_mask int,
41            @local_tempdb_mask int,
42            @pagekb int,
43            @msg varchar(1024),
44            @sptlang int,
45            @na_phrase varchar(30), /* length of German */
46            @sqlbuf varchar(1024),
47            @len1 int, @len2 int, @len3 int,
48            @q char(1), /* quote sign */
49            @instancename varchar(255),
50            @flmode_class int,
51            @flmode int,
52            @flmode_all int,
53            @flmode_desc varchar(100),
54            @holesize int,
55            @select_list varchar(255)
56    
57        if @@trancount = 0
58        begin
59            set chained off
60        end
61    
62        set transaction isolation level 1
63    
64        select @sptlang = @@langid
65    
66        if @@langid != 0
67        begin
68            if not exists (
69                    select * from master.dbo.sysmessages where error
70                        between 17050 and 17069
71                        and langid = @@langid)
72                select @sptlang = 0
73            else
74            if not exists (
75                    select * from master.dbo.sysmessages where error
76                        between 17110 and 17119
77                        and langid = @@langid)
78                select @sptlang = 0
79        end
80    
81        set nocount on
82    
83        /*
84        **  If no database name given, get 'em all.  Otherwise, count how many
85        **  databases match the specified name.
86        */
87        if @dbname is null
88            select @dbname = "%",
89                @showdev = count(*) from master.dbo.sysdatabases
90        else
91            select @showdev = count(*)
92            from master.dbo.sysdatabases
93            where name like @dbname
94    
95        /*
96        **  Sure the database exists
97        */
98        if @showdev = 0
99        begin
100           /* 17590, "The specified database does not exist." */
101           raiserror 17590
102           return (1)
103       end
104   
105       /*
106       **  Set allopts to be the sum of all possible user-settable database status
107       **  bits.  (Note that there are 2 groups of such bits.)  If we can't get
108       **  the option mask from spt_values, guess at the correct value.
109       */
110       select @allopts = number
111       from master.dbo.spt_values
112       where type = "D"
113           and name = "ALL SETTABLE OPTIONS"
114       if (@allopts is NULL)
115           select @allopts = 4 | 8 | 16 | 512 | 1024 | 2048 | 4096 | 8192
116   
117       select @all2opts = number
118       from master.dbo.spt_values
119       where type = "D2"
120           and name = "ALL SETTABLE OPTIONS"
121       if (@all2opts is NULL)
122           select @all2opts = 1 | 2 | 4 | 8 | 64
123   
124       select @all3opts = number
125       from master.dbo.spt_values
126       where type = "D3"
127           and name = "ALL SETTABLE OPTIONS"
128       if (@all3opts is NULL)
129           select @all3opts = 0
130   
131       select @all4opts = number
132       from master.dbo.spt_values
133       where type = "D4"
134           and name = "ALL SETTABLE OPTIONS"
135       if (@all4opts is NULL)
136           select @all4opts = 0
137   
138       /*
139       ** @allopts (sysdatabases.status options) should also contain some
140       ** NON-settable options that we want to check for:
141       **	 32 = "don't recover"
142       **	256 = "not recovered"
143       */
144       select @allopts = @allopts | 32 | 256
145   
146       /*
147       ** @all2opts (sysdatabases.status2 options) should also contain a
148       ** NON-settable option that we want to check for:
149       **	 16 = "offline"
150       **	128 = "has suspect objects"
151       **     1024 = "online for standby access"
152       **    32768 = "mixed log and data" 
153       */
154       select @all2opts = @all2opts | 16 | 128 | 1024 | 32768
155   
156       /*
157       ** @all3opts (sysdatabases.statu3 options) should also contain 
158       ** NON-settable options that we want to check for:
159       **
160       **	0128 = "quiesce database"
161       **	
162       **	if SMP
163       **		256 = "user created temp db"
164       **	if SDC
165       **	        256 = "local user temp db"
166       **		536870912 = "local system tempdb"
167       **		1073741824 = "global user tempdb"
168       **
169       **	1024 = "async log service"
170       **	2048 = "delayed commit"
171       **   4194304 = "archive database"
172       **   8388608 = "compressed data"
173       ** 134217728 = "compressed log"
174       */
175       select @all3opts = @all3opts | 128 | 256 | 1024 | 2048 | 4194304 | 8388608 | 134217728
176       if @@clustermode = "shared disk cluster"
177       begin
178           select @all3opts =
179               @all3opts | 536870912 | 1073741824
180           select @local_tempdb_mask = number
181           from master.dbo.spt_values
182           where type = "D3" and name = "LOCAL TEMPDB STATUS MASK"
183       end
184       else
185       begin
186           select @local_tempdb_mask = 0
187       end
188   
189       /*
190       ** @all4opts (sysdatabases.status4 options) should also contain 
191       ** NON-settable options that we want to check for:
192       **
193       **	4096 = "in-memory database"
194       **	512  = "has template"
195       **	1024 = "is template database"
196       **	
197       */
198       select @all4opts = @all4opts | 256 | 1024 | 4096 | 16777216 | 33554432,
199           @has_template_mask = 512,
200           @template_mask = 1024,
201           @imdb_mask = 4096,
202           @pgcomp_mask = 16777216,
203           @rowcomp_mask = 33554432
204   
205       /*
206       **  Since we examine the status bits in sysdatabase and turn them
207       **  into english, we need a temporary table to build the descriptions.
208       */
209       create table #spdbdesc
210       (
211           dbid smallint null,
212           dbdesc varchar(777) null
213       )
214   
215       /*
216       **  Initialize #spdbdesc from sysdatabases
217       */
218       insert into #spdbdesc(dbid)
219       select dbid
220       from master.dbo.sysdatabases
221       where name like @dbname
222       /*
223       **  Now for each dbid in #spdbdesc, build the database status
224       **  description.
225       */
226       declare @curdbid smallint /* the one we're currently working on */
227       declare @dbdesc varchar(777) /* the total description for the db */
228       declare @bitdesc varchar(30) /* the bit description for the db */
229   
230       /* For regular databases, we don't need to show the owner instances. */
231       select @showinstance = 0
232   
233       /*
234       ** Get full logging option mask for all
235       */
236       select @flmode_class = 38
237       select @flmode_all = object_info1
238       from master..sysattributes
239       where class = @flmode_class and object = 1 and attribute = 0
240   
241       select @optmax = max(object_info1)
242       from master..sysattributes
243       where class = @flmode_class and object = 1 and attribute != 0
244   
245       /*
246       **  Set @curdbid to the first dbid.
247       */
248       select @curdbid = min(dbid)
249       from #spdbdesc
250   
251       while @curdbid is not NULL
252       begin
253           /*
254           **  Initialize @dbdesc.
255           */
256           select @dbdesc = ""
257   
258           /*
259           **  Check status options (spt_values.type = "D")
260           */
261           select @thisopt = 1
262           select @optmask = @allopts /* status options */
263           while (@optmask != 0) /* until all set options noted ... */
264           begin
265               /*
266               ** If this option is user-settable, check for it
267               */
268               if (@optmask & @thisopt = @thisopt)
269               begin
270                   select @bitdesc = null
271   
272                   select @bitdesc = m.description
273                   from master.dbo.spt_values v,
274                       master.dbo.sysdatabases d,
275                       master.dbo.sysmessages m
276                   where d.dbid = @curdbid
277                       and v.type = "D"
278                       and d.status & v.number = @thisopt
279                       and v.number = @thisopt
280                       and v.msgnum = m.error
281                       and isnull(m.langid, 0) = @sptlang
282                   if @bitdesc is not null
283                   begin
284                       if @dbdesc != ""
285                           select @dbdesc = @dbdesc + ", " + @bitdesc
286                       else select @dbdesc = @bitdesc
287                   end
288   
289                   /* Turn off this status bit in the options mask */
290                   select @optmask = @optmask & ~ (@thisopt)
291               end
292   
293               /*
294               ** Get the next option bit.  Check for integer overflow for
295               ** bit 31 (0x80000000).
296               */
297               if (@thisopt < 1073741824)
298                   select @thisopt = @thisopt * 2
299               else
300                   select @thisopt = - 2147483648
301           end
302   
303           /*
304           **  Check status2 options (spt_values.type = "D2")
305           */
306           select @thisopt = 1
307           select @optmask = @all2opts /* status2 options */
308           while (@optmask != 0) /* until all set options noted ... */
309           begin
310               /*
311               ** If this option is user-settable, check for it
312               */
313               if (@optmask & @thisopt = @thisopt)
314               begin
315                   select @bitdesc = null
316   
317                   select @bitdesc = m.description
318                   from master.dbo.spt_values v,
319                       master.dbo.sysdatabases d,
320                       master.dbo.sysmessages m
321                   where d.dbid = @curdbid
322                       and v.type = "D2"
323                       and d.status2 & v.number = @thisopt
324                       and v.number = @thisopt
325                       and v.msgnum = m.error
326                       and isnull(m.langid, 0) = @sptlang
327                   if @bitdesc is not null
328                   begin
329                       if @dbdesc != ""
330                           select @dbdesc = @dbdesc + ", " + @bitdesc
331                       else select @dbdesc = @bitdesc
332                   end
333   
334                   /* Turn off this status bit in the options mask */
335                   select @optmask = @optmask & ~ (@thisopt)
336               end
337   
338               /*
339               ** Get the next option bit.  Check for integer overflow for
340               ** bit 31 (0x80000000).
341               */
342               if (@thisopt < 1073741824)
343                   select @thisopt = @thisopt * 2
344               else
345                   select @thisopt = - 2147483648
346           end
347   
348           /*
349           **  Check status3 options (spt_values.type = "D3")
350           */
351           select @thisopt = 1
352           select @optmask = @all3opts /* status3 options */
353           while (@optmask != 0) /* until all set options noted ... */
354           begin
355               /*
356               ** If this option is user-settable, check for it
357               */
358               if (@optmask & @thisopt = @thisopt)
359               begin
360                   select @bitdesc = null
361   
362                   select @bitdesc = m.description
363                   from master.dbo.spt_values v,
364                       master.dbo.sysdatabases d,
365                       master.dbo.sysmessages m
366                   where d.dbid = @curdbid
367                       and v.type = "D3"
368                       and d.status3 & v.number = @thisopt
369                       and v.number = @thisopt
370                       and v.msgnum = m.error
371                       and isnull(m.langid, 0) = @sptlang
372                   if @bitdesc is not null
373                   begin
374                       if @dbdesc != ""
375                           select @dbdesc = @dbdesc + ", " + @bitdesc
376                       else select @dbdesc = @bitdesc
377   
378                       if (@thisopt & @local_tempdb_mask = @thisopt)
379                           select @showinstance = 1
380                   end
381   
382                   /* Turn off this status bit in the options mask */
383                   select @optmask = @optmask & ~ (@thisopt)
384               end
385   
386               /*
387               ** Get the next option bit.  Check for integer overflow for
388               ** bit 31 (0x80000000).
389               */
390               if (@thisopt < 1073741824)
391                   select @thisopt = @thisopt * 2
392               else
393                   select @thisopt = - 2147483648
394           end
395   
396           /*
397           **  Check status4 options (spt_values.type = "D4")
398           */
399           select @thisopt = 1
400           select @optmask = @all4opts /* status4 options */
401           while (@optmask != 0) /* until all set options noted ... */
402           begin
403               /*
404               ** If this option is user-settable, check for it
405               */
406               if (@optmask & @thisopt = @thisopt)
407               begin
408                   select @bitdesc = null
409   
410                   select @bitdesc = m.description
411                   from master.dbo.spt_values v,
412                       master.dbo.sysdatabases d,
413                       master.dbo.sysmessages m
414                   where d.dbid = @curdbid
415                       and v.type = "D4"
416                       and d.status4 & v.number = @thisopt
417                       and v.number = @thisopt
418                       and v.msgnum = m.error
419                       and isnull(m.langid, 0) = @sptlang
420                   if @bitdesc is not null
421                   begin
422                       if @dbdesc != ""
423                           select @dbdesc = @dbdesc + ", " + @bitdesc
424                       else select @dbdesc = @bitdesc
425                   end
426   
427                   /* Turn off this status bit in the options mask */
428                   select @optmask = @optmask & ~ (@thisopt)
429               end
430   
431               /*
432               ** Get the next option bit.  Check for integer overflow for
433               ** bit 31 (0x80000000).
434               */
435               if (@thisopt < 1073741824)
436                   select @thisopt = @thisopt * 2
437               else
438                   select @thisopt = - 2147483648
439           end
440   
441           /* 
442           ** Master uses @flmode_class only to store bit names/values
443           ** but they are not applicable to master itself.
444           */
445           if @curdbid = 1
446               goto skip_flmode
447   
448           /*
449           ** Get full logging modes for this database
450           */
451           select @flmode = 0, @flmode_desc = ""
452   
453           select @flmode = object_info1
454           from master..sysattributes
455           where class = @flmode_class and object = @curdbid and attribute = 0
456   
457           if (@flmode = @flmode_all)
458           begin
459               select @flmode_desc = "full logging for all"
460               select @flmode = 0
461           end
462   
463           select @thisopt = 1
464           select @optmask = @flmode
465           while ((@optmask != 0) and (@thisopt <= @optmax))
466           begin
467               if (@optmask & @thisopt != 0)
468               begin
469                   select @bitdesc = char_value
470                   from master..sysattributes
471                   where class = @flmode_class
472                       and object = 1
473                       and object_info1 = @thisopt
474   
475                   if @bitdesc is not null
476                   begin
477                       if (@flmode_desc = "")
478                           select @flmode_desc = "full logging for "
479                               + @bitdesc
480                       else
481                           select @flmode_desc = @flmode_desc + "/"
482                               + @bitdesc
483                   end
484                   select @optmask = @optmask & ~ (@thisopt)
485               end
486   
487               if (@thisopt < 1073741824)
488                   select @thisopt = @thisopt * 2
489               else
490                   select @thisopt = - 2147483648
491           end
492   
493           if (@flmode_desc != "")
494           begin
495               if (@dbdesc != "")
496                   select @dbdesc = @dbdesc + "," + @flmode_desc
497               else
498                   select @dbdesc = @flmode_desc
499           end
500   
501   skip_flmode:
502   
503           /*
504           **  If no flags are set, say so.
505           */
506           if (@dbdesc = "")
507           begin
508               /* 17591, "no options set" */
509               exec sp_getmessage 17591, @dbdesc out
510           end
511   
512           /*
513           **  Save the description.
514           */
515           update #spdbdesc
516           set dbdesc = @dbdesc
517           from #spdbdesc
518           where dbid = @curdbid
519   
520           /*
521           **  Now get the next, if any dbid.
522           */
523           select @curdbid = min(dbid)
524           from #spdbdesc
525           where dbid > @curdbid
526       end
527   
528       /* 
529       ** Get the rows of interest from sysusages into a temp table.  This is to
530       ** avoid deadlocking with create table, which could happen if we directly
531       ** join sysdatabases and sysusages.
532       ** Mark as log only those fragments that have segmap = 0 but location
533       ** set as read only log. They are an intermediate step in the
534       ** log shrink process.
535       */
536       select u.dbid, segmap = case when u.location = 6 and u.segmap = 0
537               then 4 else u.segmap
538           end,
539           u.lstart, u.size, u.vdevno,
540           u.unreservedpgs, u.crdate
541       into #spdbusages
542       from #spdbdesc, master.dbo.sysusages u
543       where #spdbdesc.dbid = u.dbid
544           and u.vdevno >= 0
545   
546   
547       /*	
548       ** Compute number of Pages in a Megabyte.
549       */
550       declare @numpgsmb float /* Number of Pages per Megabyte */
551   
552       select @numpgsmb = (1048576. / v.low)
553       from master.dbo.spt_values v
554       where v.number = 1
555           and v.type = "E"
556   
557       /*
558       **  Now #spdbdesc is complete so we can print out the db info
559       */
560   
561       select distinct name = d.name,
562           db_size = str(sum(u.size) / @numpgsmb, 10, 1)
563           + " MB",
564           owner = suser_name(d.suid),
565           dbid = d.dbid,
566           created = convert(char(18), d.crdate, 107),
567           durability = db_attr(d.dbid, 'durability'),
568           lobcomplvl = d.lobcomp_lvl,
569           d.inrowlen,
570           status = #spdbdesc.dbdesc
571   
572       into #sphelpdb1rs
573       from master.dbo.sysdatabases d,
574           #spdbusages u, #spdbdesc
575       where d.dbid = #spdbdesc.dbid
576           and #spdbdesc.dbid = u.dbid
577       group by #spdbdesc.dbid
578       having d.dbid = #spdbdesc.dbid
579           and #spdbdesc.dbid = u.dbid
580   
581   
582       /*
583       ** Print the owner instance name only if the database name is specified
584       ** and the database is a local tempdb (@showinstance = 1)
585       */
586       select @select_list = "name, db_size, owner, dbid, created, durability, lobcomplvl, inrowlen, status"
587   
588       exec sp_autoformat @fulltabname = #sphelpdb1rs
589           , @selectlist = @select_list
590           , @orderby = "order by 1"
591   
592   
593       /*  
594       ** Print sysattributes data if there is any.  The join with multiple
595       ** instances of sysattributes is to get the string descriptions for
596       ** the class (master..sysattributes cn) and the attribute
597       ** (master..sysattributes an). These should never be longer than
598       ** 30 characters, so it's okay to truncate them.
599       */
600   
601       select name = db.name, attribute_class =
602           convert(varchar(512), cn.char_value),
603           attribute = convert(varchar(512), an.char_value), a.int_value,
604           char_value = convert(varchar(512), a.char_value), a.comments,
605           class = a.class,
606           attribute_id = a.attribute
607       into #spdbattr
608       from master.dbo.sysdatabases db, #spdbdesc d,
609           master.dbo.sysattributes a, master.dbo.sysattributes an,
610           master.dbo.sysattributes cn
611       where db.dbid = d.dbid
612           and a.class != @flmode_class
613           and a.class = cn.object
614           and a.attribute = an.object_info1
615           and a.class = an.object
616           and a.object_type = "D"
617           and a.object = d.dbid
618           and cn.class = 0
619           and cn.attribute = 0
620           and an.class = 0
621           and an.attribute = 1
622           and a.object = db.dbid
623   
624       /*
625       ** It's possible a cache is deleted without doing an unbind first. After
626       ** a server reboot the binding is marked 'invalid' (int_value = 0).
627       ** If we have such an invalid binding, don't show it in the output.
628       */
629       delete from #spdbattr
630       where class = 3
631           and attribute_id = 0
632           and int_value = 0
633   
634       if exists (select * from #spdbattr)
635       begin
636           exec sp_autoformat @fulltabname = #spdbattr,
637               @selectlist = "name, attribute_class, attribute, int_value,char_value,comments"
638       end
639   
640   
641   
642       if @showdev = 1
643       begin
644           select @curdbid = dbid /* database ID */
645           from master.dbo.sysdatabases
646           where name like @dbname
647           select @pagekb = (low / 1024) /* kbytes per page */
648           from master.dbo.spt_values
649           where number = 1
650               and type = 'E'
651   
652           /* 17714, "not applicable" */
653           select @na_phrase = description
654           from master.dbo.sysmessages
655           where error = 17714
656               and isnull(langid, 0) = @sptlang
657   
658           /* Check the length of the usage column */
659           select distinct @len3 = max(datalength(m.description))
660           from master.dbo.sysdatabases d, #spdbusages u, master.dbo.sysdevices v,
661               master.dbo.spt_values b, master.dbo.sysmessages m
662           where d.dbid = u.dbid
663               and u.vdevno = v.vdevno
664               and ((v.status & 2 = 2) or (v.status2 & 8 = 8))
665               and d.name like @dbname
666               and b.type = "S"
667               and u.segmap & 7 = b.number
668               and b.msgnum = m.error
669               and isnull(m.langid, 0) = @sptlang
670   
671           /*
672           ** Order the device fragments output by sysusages.lstart unless
673           ** the 2nd parameter of sp_helpdb is "device_name"
674           */
675           if (@order = "device_name")
676           begin
677               select @order = "v.name"
678           end
679           else
680           begin
681               if (@order != "lstart")
682               begin
683                   /*
684                   ** 17600, "sp_helpdb: order value '%1!' is not valid. 
685                   ** Valid values are 'lstart' and 'device_name'. 
686                   ** Using default value 'lstart'."
687                   */
688                   raiserror 17600, @order
689               end
690   
691               /* Fragment order same as order in create/alter database */
692               select @order = "u.lstart"
693   
694           end
695   
696           if (@len3 < 20)
697               select @len3 = 20
698   
699           select @q = substring('''', 1, 1)
700   
701           select @sqlbuf =
702               'select device_fragments = v.name, size =
703   			str(size / ' + str(@numpgsmb, 10, 1) + ', 10, 1) + '
704               + @q + ' MB' + @q + ',
705   		usage = convert(char('
706               + convert(varchar, @len3) + '), m.description),
707   		created = convert(char(25), u.crdate, 100),
708   		case
709   			when u.segmap = 4 then ' + @q + @na_phrase + @q
710               + ' else 
711   			str((curunreservedpgs(d.dbid, u.lstart,
712   				u.unreservedpgs) * '
713               + convert(varchar, @pagekb) + '), 16)
714   		end "free kbytes"
715   	    from master.dbo.sysdatabases d,
716   		 #spdbusages u,
717   		 master.dbo.sysdevices v,
718   		 master.dbo.spt_values b,
719   		 master.dbo.sysmessages m
720   		where d.dbid = u.dbid
721   			and u.vdevno = v.vdevno
722   			and ((v.status & 2 = 2)  or (v.status2 & 8 = 8))
723   			and d.name = ' + @q + @dbname + @q + '
724   			and b.type = ' + @q + 'S' + @q + '
725   			and u.segmap & 7 = b.number
726   			and b.msgnum = m.error
727   			and isnull(m.langid, 0) = '
728               + convert(varchar, @sptlang) +
729               ' order by ' + @order
730   
731           exec (@sqlbuf)
732   
733           /* 
734           ** If log segment free space wasn't selected above, select it now.
735           ** Skip this step if the database is in load (32), not recovered (64)
736           ** in bypass recovery (128), suspect (256), offline (64)
737           */
738           select @sqlbuf = ""
739           if exists (select *
740                   from master.dbo.sysdatabases d, master.dbo.sysusages u
741                   where d.name like @dbname
742                       and d.dbid = u.dbid
743                       and u.segmap = 4
744                       and (d.status & (32 + 64 + 128 + 256) = 0)
745                       and (d.status2 & 64) = 0)
746   
747           begin
748               /* 17111, "log only".  Length 17 is for French, the longest */
749               select @sqlbuf = substring((select description
750                           from master.dbo.sysmessages
751                           where error = 17111
752                               and isnull(langid, 0) = @sptlang), 1, 17)
753                   + " " + "free kbytes" + " = "
754                   + convert(char, (lct_admin("logsegment_freepages", @curdbid)
755                   - lct_admin("reserved_for_rollbacks", @curdbid))
756                   * @pagekb)
757           end
758   
759           /* If there are log holes in the database, show the size. */
760           select @holesize = sum(size)
761           from master.dbo.sysusages
762           where dbid = @curdbid
763               and vstart = lstart
764               and vdevno = - @curdbid
765               and segmap = 0
766   
767           if (@holesize > 0)
768           begin
769               if (@sqlbuf != "")
770                   select @sqlbuf = rtrim(@sqlbuf) + ", "
771   
772               /* 17909, "log only unavailable" */
773               select @sqlbuf = @sqlbuf + substring((select description
774                           from master.dbo.sysmessages
775                           where error = 17909
776                               and isnull(langid, 0) = @sptlang), 1, 20)
777                   + " kbytes = " + convert(char, @holesize * @pagekb)
778           end
779   
780           if (@sqlbuf != "")
781               select substring(@sqlbuf, 1, 70)
782   
783           /*
784           **  If there is only one database and we are in it, show the
785           **  segments.
786           */
787           if exists (select *
788                   from #spdbdesc
789                   where db_id() = dbid)
790           begin
791               declare @curdevice varchar(255),
792                   @curseg smallint,
793                   @segbit int
794   
795               delete #spdbdesc
796   
797               select @curdevice = min(d.name)
798               from #spdbusages u, master.dbo.sysdevices d
799               where u.dbid = db_id()
800                   and u.vdevno = d.vdevno
801                   and ((d.status & 2 = 2) or (d.status2 & 8 = 8))
802               while (@curdevice is not null)
803               begin
804                   /*
805                   ** We need an inner loop here to go through
806                   **  all the possible segment.
807                   */
808                   select @curseg = min(segment)
809                   from syssegments
810                   while (@curseg is not null)
811                   begin
812                       if (@curseg < 31)
813                           select @segbit = power(2, @curseg)
814                       else select @segbit = low
815                           from master.dbo.spt_values
816                           where type = "E"
817                               and number = 2
818                       insert into #spdbdesc
819                       select @curseg, @curdevice
820                       from #spdbusages u,
821                           master.dbo.sysdevices d,
822                           master.dbo.spt_values v
823                       where u.segmap & @segbit = @segbit
824                           and u.vdevno = d.vdevno
825                           and u.dbid = db_id()
826                           and ((d.status & 2 = 2) or (d.status2 & 8 = 8))
827                           and v.number = 1
828                           and v.type = "E"
829                           and d.name = @curdevice
830                       select @curseg = min(segment)
831                       from syssegments
832                       where segment > @curseg
833                   end
834   
835                   select @curdevice = min(d.name)
836                   from #spdbusages u,
837                       master.dbo.sysdevices d
838                   where u.dbid = db_id()
839                       and u.vdevno = d.vdevno
840                       and ((d.status & 2 = 2) or (d.status2 & 8 = 8))
841                       and d.name > @curdevice
842               end
843   
844               /*
845               **  One last check for any devices that have no segments.
846               */
847               insert into #spdbdesc
848               select null, d.name
849               from #spdbusages u,
850                   master.dbo.sysdevices d
851               where u.segmap = 0
852                   and u.vdevno = d.vdevno
853                   and u.dbid = db_id()
854                   and ((d.status & 2 = 2) or (d.status2 & 8 = 8))
855   
856               /* 17592, " -- unused by any segments --" */
857               exec sp_getmessage 17592, @msg out
858   
859               select distinct device = dbdesc,
860                   segment = isnull(name, @msg)
861               into #sphelpdb2rs
862               from #spdbdesc, syssegments
863               where dbid *= segment
864               exec sp_autoformat @fulltabname = #sphelpdb2rs,
865                   @orderby = "order by 1, 2"
866               drop table #sphelpdb2rs
867           end
868   
869           /*
870           ** If the given database is a template database then
871           ** print all the database created from it.
872           */
873           select @dbstatus4 = d.status4
874           from master.dbo.sysdatabases d
875           where name like @dbname
876   
877           /*
878           ** OMNI: Display the default location for remote tables
879           **       if one exists.
880           **
881           ** IMDB: In case of in-memory database def_remote_loc is
882           ** used to store the template database associated with the
883           ** in-memory database.
884           */
885           if exists (select *
886                   from master.dbo.sysdatabases
887                   where name like @dbname
888                       and def_remote_loc is not null)
889           begin --{
890               if ((@dbstatus4 & @has_template_mask) != 0)
891               begin --{
892                   select "template_database"
893                       = substring(def_remote_loc, 1, 30)
894                   from master.dbo.sysdatabases
895                   where name like @dbname
896               end --}
897               else
898               begin --{
899                   select "remote location" =
900                       substring(def_remote_loc, 1, 77)
901                   from master.dbo.sysdatabases
902                   where name like @dbname
903               end --}
904           end --}
905   
906           if ((@dbstatus4 & @template_mask) = @template_mask)
907           begin --{
908               select template_for = name
909               into #templateddbs
910               from master.dbo.sysdatabases
911               where def_remote_loc like @dbname
912   
913               exec sp_autoformat @fulltabname = #templateddbs
914           end --}
915       end
916   
917       drop table #spdbdesc
918       drop table #spdbattr
919       return (0)
920   


exec sp_procxmode 'sp_helpdb', 'AnyMode'
go

Grant Execute on sp_helpdb to public
go
RESULT SETS
sp_helpdb_rset_003
sp_helpdb_rset_002
sp_helpdb_rset_001

DEFECTS
 QBGB 6 Bad group by d.name 561
 QCAR 6 Cartesian product between tables #spdbusages u and [master..spt_values v] 820
 QJWI 5 Join or Sarg Without Index 278
 QJWI 5 Join or Sarg Without Index 323
 QJWI 5 Join or Sarg Without Index 368
 QJWI 5 Join or Sarg Without Index 416
 MEST 4 Empty String will be replaced by Single Space 256
 MEST 4 Empty String will be replaced by Single Space 284
 MEST 4 Empty String will be replaced by Single Space 329
 MEST 4 Empty String will be replaced by Single Space 374
 MEST 4 Empty String will be replaced by Single Space 422
 MEST 4 Empty String will be replaced by Single Space 451
 MEST 4 Empty String will be replaced by Single Space 477
 MEST 4 Empty String will be replaced by Single Space 493
 MEST 4 Empty String will be replaced by Single Space 495
 MEST 4 Empty String will be replaced by Single Space 506
 MEST 4 Empty String will be replaced by Single Space 738
 MEST 4 Empty String will be replaced by Single Space 769
 MEST 4 Empty String will be replaced by Single Space 780
 MINU 4 Unique Index with nullable columns master..sysattributes master..sysattributes
 MINU 4 Unique Index with nullable columns master..sysmessages master..sysmessages
 MTYP 4 Assignment type mismatch @bitdesc: varchar(30) = varchar(1024) 272
 MTYP 4 Assignment type mismatch @bitdesc: varchar(30) = varchar(1024) 317
 MTYP 4 Assignment type mismatch @bitdesc: varchar(30) = varchar(1024) 362
 MTYP 4 Assignment type mismatch @bitdesc: varchar(30) = varchar(1024) 410
 MTYP 4 Assignment type mismatch @bitdesc: varchar(30) = varchar(768) 469
 MTYP 4 Assignment type mismatch @na_phrase: varchar(30) = varchar(1024) 653
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 588
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 636
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 864
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 913
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
112
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
119
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
126
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
133
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
182
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use JOIN Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object}
Uncovered: [object_type, object_info1, object_info2, object_info3, object_cinfo]
613
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use JOIN Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object, object_info1}
Uncovered: [object_type, object_info2, object_info3, object_cinfo]
614
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
666
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 71
 QTYP 4 Comparison type mismatch smallint = int 71
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 77
 QTYP 4 Comparison type mismatch smallint = int 77
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 239
 QTYP 4 Comparison type mismatch smallint = int 239
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 243
 QTYP 4 Comparison type mismatch smallint = int 243
 QTYP 4 Comparison type mismatch Comparison type mismatch: int vs smallint 455
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 455
 QTYP 4 Comparison type mismatch smallint = int 455
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 471
 QTYP 4 Comparison type mismatch smallint = int 471
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 536
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 612
 QTYP 4 Comparison type mismatch smallint = int 612
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 613
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 614
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 615
 QTYP 4 Comparison type mismatch Comparison type mismatch: int vs smallint 617
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 618
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 619
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 620
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 621
 QTYP 4 Comparison type mismatch Comparison type mismatch: int vs smallint 622
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 630
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 631
 QTYP 4 Comparison type mismatch Comparison type mismatch: int vs smallint 764
 QTYP 4 Comparison type mismatch Comparison type mismatch: int vs smallint 789
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 799
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 825
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 838
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 853
 TNOI 4 Table with no index sybsystemprocs..syssegments sybsystemprocs..syssegments
 TNOU 4 Table with no unique index master..spt_values master..spt_values
 MDYN 3 Proc uses Dynamic SQL but is not flagged with Dynamic Ownership Chain 19
 MGTP 3 Grant to public master..spt_values  
 MGTP 3 Grant to public master..sysattributes  
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public master..sysdevices  
 MGTP 3 Grant to public master..sysmessages  
 MGTP 3 Grant to public master..sysusages  
 MGTP 3 Grant to public sybsystemprocs..sp_helpdb  
 MGTP 3 Grant to public sybsystemprocs..syssegments  
 MNER 3 No Error Check should check @@error after insert 218
 MNER 3 No Error Check should check return value of exec 509
 MNER 3 No Error Check should check @@error after update 515
 MNER 3 No Error Check should check @@error after select into 536
 MNER 3 No Error Check should check @@error after select into 561
 MNER 3 No Error Check should check return value of exec 588
 MNER 3 No Error Check should check @@error after select into 601
 MNER 3 No Error Check should check @@error after delete 629
 MNER 3 No Error Check should check return value of exec 636
 MNER 3 No Error Check should check @@error after delete 795
 MNER 3 No Error Check should check @@error after insert 818
 MNER 3 No Error Check should check @@error after insert 847
 MNER 3 No Error Check should check return value of exec 857
 MNER 3 No Error Check should check @@error after select into 859
 MNER 3 No Error Check should check return value of exec 864
 MNER 3 No Error Check should check @@error after select into 908
 MNER 3 No Error Check should check return value of exec 913
 MUCO 3 Useless Code Useless Brackets 102
 MUCO 3 Useless Code Useless Brackets 114
 MUCO 3 Useless Code Useless Brackets 121
 MUCO 3 Useless Code Useless Brackets 128
 MUCO 3 Useless Code Useless Brackets 135
 MUCO 3 Useless Code Useless Brackets 263
 MUCO 3 Useless Code Useless Brackets 268
 MUCO 3 Useless Code Useless Brackets 297
 MUCO 3 Useless Code Useless Brackets 308
 MUCO 3 Useless Code Useless Brackets 313
 MUCO 3 Useless Code Useless Brackets 342
 MUCO 3 Useless Code Useless Brackets 353
 MUCO 3 Useless Code Useless Brackets 358
 MUCO 3 Useless Code Useless Brackets 378
 MUCO 3 Useless Code Useless Brackets 390
 MUCO 3 Useless Code Useless Brackets 401
 MUCO 3 Useless Code Useless Brackets 406
 MUCO 3 Useless Code Useless Brackets 435
 MUCO 3 Useless Code Useless Brackets 457
 MUCO 3 Useless Code Useless Brackets 465
 MUCO 3 Useless Code Useless Brackets 467
 MUCO 3 Useless Code Useless Brackets 477
 MUCO 3 Useless Code Useless Brackets 487
 MUCO 3 Useless Code Useless Brackets 493
 MUCO 3 Useless Code Useless Brackets 495
 MUCO 3 Useless Code Useless Brackets 506
 MUCO 3 Useless Code Useless Brackets 552
 MUCO 3 Useless Code Useless Brackets 647
 MUCO 3 Useless Code Useless Brackets 675
 MUCO 3 Useless Code Useless Brackets 681
 MUCO 3 Useless Code Useless Brackets 696
 MUCO 3 Useless Code Useless Brackets 767
 MUCO 3 Useless Code Useless Brackets 769
 MUCO 3 Useless Code Useless Brackets 780
 MUCO 3 Useless Code Useless Brackets 802
 MUCO 3 Useless Code Useless Brackets 810
 MUCO 3 Useless Code Useless Brackets 812
 MUCO 3 Useless Code Useless Brackets 890
 MUCO 3 Useless Code Useless Brackets 906
 MUCO 3 Useless Code Useless Brackets 919
 MUUF 3 Update or Delete with Useless From Clause 515
 QAFM 3 Var Assignment from potentially many rows 110
 QAFM 3 Var Assignment from potentially many rows 117
 QAFM 3 Var Assignment from potentially many rows 124
 QAFM 3 Var Assignment from potentially many rows 131
 QAFM 3 Var Assignment from potentially many rows 180
 QAFM 3 Var Assignment from potentially many rows 237
 QAFM 3 Var Assignment from potentially many rows 453
 QAFM 3 Var Assignment from potentially many rows 469
 QAFM 3 Var Assignment from potentially many rows 552
 QAFM 3 Var Assignment from potentially many rows 644
 QAFM 3 Var Assignment from potentially many rows 647
 QAFM 3 Var Assignment from potentially many rows 653
 QAFM 3 Var Assignment from potentially many rows 814
 QAFM 3 Var Assignment from potentially many rows 873
 QCRS 3 Conditional Result Set 781
 QCRS 3 Conditional Result Set 892
 QCRS 3 Conditional Result Set 899
 QCTC 3 Conditional Table Creation 859
 QCTC 3 Conditional Table Creation 908
 QDIS 3 Check correct use of 'select distinct' 561
 QDIS 3 Check correct use of 'select distinct' 659
 QDIS 3 Check correct use of 'select distinct' 859
 QGWO 3 Group by/Distinct/Union without order by 561
 QGWO 3 Group by/Distinct/Union without order by 659
 QGWO 3 Group by/Distinct/Union without order by 859
 QISO 3 Set isolation level 62
 QIWC 3 Insert with not all columns specified missing 1 columns out of 2 218
 QJWT 3 Join or Sarg Without Index on temp table 543
 QJWT 3 Join or Sarg Without Index on temp table 575
 QJWT 3 Join or Sarg Without Index on temp table 576
 QJWT 3 Join or Sarg Without Index on temp table 578
 QJWT 3 Join or Sarg Without Index on temp table 579
 QJWT 3 Join or Sarg Without Index on temp table 611
 QJWT 3 Join or Sarg Without Index on temp table 617
 QJWT 3 Join or Sarg Without Index on temp table 662
 QJWT 3 Join or Sarg Without Index on temp table 663
 QJWT 3 Join or Sarg Without Index on temp table 667
 QJWT 3 Join or Sarg Without Index on temp table 800
 QJWT 3 Join or Sarg Without Index on temp table 824
 QJWT 3 Join or Sarg Without Index on temp table 839
 QJWT 3 Join or Sarg Without Index on temp table 852
 QJWT 3 Join or Sarg Without Index on temp table 863
 QNAJ 3 Not using ANSI Inner Join 273
 QNAJ 3 Not using ANSI Inner Join 318
 QNAJ 3 Not using ANSI Inner Join 363
 QNAJ 3 Not using ANSI Inner Join 411
 QNAJ 3 Not using ANSI Inner Join 542
 QNAJ 3 Not using ANSI Inner Join 573
 QNAJ 3 Not using ANSI Inner Join 608
 QNAJ 3 Not using ANSI Inner Join 660
 QNAJ 3 Not using ANSI Inner Join 740
 QNAJ 3 Not using ANSI Inner Join 798
 QNAJ 3 Not using ANSI Inner Join 820
 QNAJ 3 Not using ANSI Inner Join 836
 QNAJ 3 Not using ANSI Inner Join 849
 QNAM 3 Select expression has no name substring(@sqlbuf, 1, 70) 781
 QNAO 3 Not using ANSI Outer Join 862
 QNCO 3 No column in result set 819
 QNUA 3 Should use Alias: Table #spdbdesc 542
 QNUA 3 Should use Alias: Table #spdbdesc 574
 QNUA 3 Should use Alias: Column dbdesc should use alias #spdbdesc 859
 QNUA 3 Should use Alias: Column name should use alias syssegments 860
 QNUA 3 Should use Alias: Table #spdbdesc 862
 QNUA 3 Should use Alias: Table sybsystemprocs..syssegments 862
 QNUA 3 Should use Alias: Column dbid should use alias #spdbdesc 863
 QNUA 3 Should use Alias: Column segment should use alias syssegments 863
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
69
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
75
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object, class, attribute}
239
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object, class, attribute}
243
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error}
Uncovered: [dlevel]
280
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error}
Uncovered: [dlevel]
325
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error}
Uncovered: [dlevel]
370
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error}
Uncovered: [dlevel]
418
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object, class, attribute}
455
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object, class, object_info1}
471
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysusages.ncsysusages unique
(vdevno, vstart)
Intersection: {vdevno}
544
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {class}
Uncovered: [attribute, object, object_info1, object_info2, object_info3, object_cinfo]
613
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {class, attribute}
Uncovered: [object, object_info1, object_info2, object_info3, object_cinfo]
614
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
655
 QPRI 3 Join or Sarg with Rooted Partial Index Use JOIN Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error}
Uncovered: [dlevel]
668
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
751
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysusages.csysusages unique clustered
(dbid, lstart)
Intersection: {dbid}
762
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
775
 QSWV 3 Sarg with variable @thisopt, Candidate Index: spt_values.spt_valuesclust clustered(number, type) F 279
 QSWV 3 Sarg with variable @thisopt, Candidate Index: spt_values.spt_valuesclust clustered(number, type) F 324
 QSWV 3 Sarg with variable @thisopt, Candidate Index: spt_values.spt_valuesclust clustered(number, type) F 369
 QSWV 3 Sarg with variable @thisopt, Candidate Index: spt_values.spt_valuesclust clustered(number, type) F 417
 QTJ1 3 Table only appears in inner join clause 542
 VNRD 3 Variable is not read @imdb_mask 201
 VNRD 3 Variable is not read @pgcomp_mask 202
 VNRD 3 Variable is not read @rowcomp_mask 203
 VUNU 3 Variable is not used @len1 47
 VUNU 3 Variable is not used @len2 47
 VUNU 3 Variable is not used @instancename 49
 MDYS 2 Dynamic SQL Marker 731
 MRST 2 Result Set Marker 781
 MRST 2 Result Set Marker 892
 MRST 2 Result Set Marker 899
 MSUB 2 Subquery Marker 68
 MSUB 2 Subquery Marker 74
 MSUB 2 Subquery Marker 739
 MSUB 2 Subquery Marker 749
 MSUB 2 Subquery Marker 773
 MSUB 2 Subquery Marker 787
 MSUB 2 Subquery Marker 885
 MTR1 2 Metrics: Comments Ratio Comments: 29% 19
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 141 = 141dec - 2exi + 2 19
 MTR3 2 Metrics: Query Complexity Complexity: 487 19
 PRED_QUERY_COLLECTION 2 {d=master..sysdatabases, u=master..sysusages} 0 739

DEPENDENCIES
PROCS AND TABLES USED
reads table sybsystemprocs..syssegments  
reads table master..spt_values (1)  
read_writes table tempdb..#spdbusages (1) 
reads table master..sysmessages (1)  
writes table tempdb..#templateddbs (1) 
writes table tempdb..#sphelpdb1rs (1) 
read_writes table tempdb..#spdbdesc (1) 
reads table master..sysdevices (1)  
reads table master..sysusages (1)  
reads table master..sysdatabases (1)  
calls proc sybsystemprocs..sp_autoformat  
   reads table master..syscolumns (1)  
   read_writes table tempdb..#colinfo_af (1) 
   reads table tempdb..syscolumns (1)  
   reads table master..systypes (1)  
   calls proc sybsystemprocs..sp_autoformat  
   reads table tempdb..systypes (1)  
   calls proc sybsystemprocs..sp_namecrack  
read_writes table tempdb..#spdbattr (1) 
calls proc sybsystemprocs..sp_getmessage  
   reads table sybsystemprocs..sysusermessages  
   reads table master..sysmessages (1)  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table master..syslanguages (1)  
reads table master..sysattributes (1)  
writes table tempdb..#sphelpdb2rs (1)