DatabaseProcApplicationCreatedLinks
sybsystemprocssp_rename  14 déc. 14Defects Propagation Dependencies

1     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
2     /*	4.8	1.1	06/14/90	sproc/src/password */
3     
4     /*
5     ** IMPORTANT NOTE:
6     ** This stored procedure uses the built-in function object_id() in the
7     ** where clause of a select query. If you intend to change this query
8     ** or use the object_id() or db_id() builtin in this procedure, please read the
9     ** READ.ME file in the $DBMS/generic/sproc directory to ensure that the rules
10    ** pertaining to object-id's and db-id's outlined there, are followed.
11    **
12    ** NOTE:
13    ** All updates to sysindexes are done by forcing the index access via
14    ** 'csysindexes' so that it's clear that only one row is being updated.
15    ** (Multi-row updates to sysindexes are prohibited.)
16    */
17    
18    create or replace procedure sp_rename
19        @objname varchar(768), /* old (current) object name */
20        @newname varchar(256), /* new name we want to call it */
21        @indorcolorpar varchar(12) = null /* Index or column to rename */
22    as
23    
24        declare @objid int /* object id of the thing to rename */
25            , @index_objid int /* object id from sysindexes */
26            , @partition_objid int /* object id from syspartitions */
27            , @msg varchar(1024)
28            , @dbid int
29            , @temp_dbid int
30            , @temp_objid int
31            , @curdb_name varchar(255) /* name of current db */
32            , @rep_constant smallint /* bit indicating a repl. object */
33            , @cur_sysstat smallint /* current sysstat value of object */
34            , @rep_obj int /* is the object replicated? */
35            , @rep_db_stat int /* rep status of database */
36            , @rep_db int /* is the db replicated */
37            , @table_or_proc int /* object is a table or procedure */
38            , @obj_type char(2) /* type of the object */
39            , @user_tran int /* inside a user tran? */
40            , @after_image int /* log the after image of the schema */
41            , @mod_versionts int /* modify version timestamp after
42            ** logging the schema
43            */
44            , @dbname varchar(255)
45            , @maxobjlen int /* length of sysobject.name from syscolumns */
46            , @maxuserlen int /* length of sysusers.name from syscolumns */
47            , @maxtotlen int /* Total length of sysobjects.name + sysusers.name*/
48            , @lt_rep_get_failed
49            int
50            , @lt_rep_all int
51            , @lt_rep_l1 int
52            , @tabname varchar(255) /* name of table */
53            , @colname varchar(255) /* name of column */
54            , @ptnname varchar(255) /* name of partition */
55            , @indname varchar(255) /* name of index */
56            , @twopartname varchar(255) /* name of partition */
57            , @indid int /* Index ID */
58            , @colid int /* colid of the column */
59            , @ptnid int /* id of partition being renamed. */
60            , @tabobjid int /* Table id */
61            , @dotloc int /* offset of '.' in @objname */
62            , @dotloc2 int /* offset of '.' in @twopartname */
63            , @error int /* Cache @@error */
64            , @rowcount int /* Cache @@rowcount */
65    
66        /*
67        ** Running sp_rename inside a transaction would endanger the
68        ** recoverability of the transaction/database. Disallow it.
69        ** Do the @@trancount check before initializing any local variables,
70        ** because "select" statement itself will start a transaction
71        ** if chained mode is on.
72        */
73        if @@trancount > 0
74        begin
75            /*
76            ** 17260, "Can't run %1! from within a transaction."
77            */
78            raiserror 17260, "sp_rename"
79            return (1)
80        end
81        else
82        begin
83            set chained off
84        end
85    
86        /*
87        ** Initialise objid and index_objid
88        */
89        select @objid = NULL
90            , @index_objid = NULL
91        /* 
92        ** check the length of sysobject.name and sysuser.name 
93        */
94        select @maxobjlen = length from syscolumns
95        where id = object_id("sysobjects") and
96            name = 'name'
97        select @maxuserlen = length from syscolumns
98        where id = object_id("sysusers") and
99            name = 'name'
100   
101   
102       if @objname like "%.%.%"
103       begin
104           select @maxtotlen = (3 * @maxobjlen) + 2
105       end
106       else
107       begin
108           select @maxtotlen = (@maxobjlen + @maxuserlen) + 1
109       end
110   
111       /* check the lengths of the input params */
112       if char_length(@objname) > @maxtotlen
113       begin
114           /*
115           ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
116           */
117           raiserror 17325, @objname, @maxtotlen
118           return (1)
119       end
120   
121       if char_length(@newname) > @maxobjlen
122       begin
123           /*
124           ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
125           */
126           raiserror 17325, @newname, @maxobjlen
127           return (1)
128       end
129       if ((@indorcolorpar is not null)
130               and (@indorcolorpar not in ('index', 'column', 'partition')))
131       begin
132           /*
133           ** 18938, "Invalid third argument '%1!' entered. Valid values are 
134           ** :'%2!'"
135           */
136           raiserror 18938, @indorcolorpar, "'index', 'column', 'partition'"
137           return (1)
138       end
139   
140       /*
141       **  Check to see that the @newname is valid.
142       */
143       if valid_name(@newname, @maxobjlen) = 0
144       begin
145           /*
146           ** 17240, "'%1!' is not a valid name."
147           */
148           raiserror 17240, @newname
149           return (1)
150       end
151   
152       /*
153       ** Replication constants.
154       */
155       select @lt_rep_get_failed = - 2, @lt_rep_all = 2048, @lt_rep_l1 = 4096
156   
157       set transaction isolation level 1
158   
159       set @dbid = db_id()
160   
161       if @objname like "%.%.%"
162       begin
163           /* 
164           ** 3-part names are only meaningful when the 3rd argument is
165           ** 'partition'. Flag any other combination with an error.
166           */
167           if (@indorcolorpar IN ('index', 'column'))
168           begin
169               set @msg = "'" + @objname + "," + @indorcolorpar + "'"
170               raiserror 19614, @msg
171               return (1)
172   
173           end
174   
175           else if (@indorcolorpar = null or @indorcolorpar = 'partition')
176           begin
177               /* Get the table name, indexname and partition name out. */
178               select @dotloc = charindex(".", @objname)
179   
180               select @tabname = substring(@objname, 1, (@dotloc - 1))
181               select @twopartname = substring(@objname, (@dotloc + 1), @maxtotlen)
182               select @dotloc2 = charindex(".", @twopartname)
183               select @indname = substring(@twopartname, 1, (@dotloc2 - 1))
184               select @ptnname = substring(@twopartname, (@dotloc2 + 1), @maxtotlen)
185   
186               select @partition_objid = p.id,
187                   @indid = p.indid,
188                   @ptnid = p.partitionid
189               from sysobjects o, sysindexes i, syspartitions p
190               where o.name = @tabname
191                   and o.uid = user_id()
192                   and o.sysstat & 7 = 3 /* user table */
193                   and i.name = @indname
194                   and i.indid != 0
195                   and p.name = @ptnname
196                   and o.id = i.id
197                   and i.id = p.id
198                   and i.indid = p.indid
199   
200               /*
201               **  Now We have the objid from syspartitions.
202               */
203               set @objid = @partition_objid
204   
205               /*
206               **  If @objid is NULL then that means it isn't an
207               **  valid partition name.
208               */
209               if @objid is null
210               begin
211                   /*
212                   ** 17782, "You do not own a table, column, index or
213                   ** partition of that name in the current database."
214                   */
215                   raiserror 17782
216                   return (1)
217               end
218   
219               /*
220               **  Check to make sure that there is no already a partition
221               **  that has the new name.
222               */
223               if exists (select *
224                       from syspartitions
225                       where id = @objid
226                           and indid = @indid
227                           and name = @newname)
228               begin
229                   /*
230                   ** 17163, "There is already a partition named '%1!' for index '%2!'."
231                   */
232                   raiserror 17163, @newname, @indname
233                   return (1)
234               end
235   
236               /*
237               ** IMPORTANT: The name rs_logexec is significant
238               ** and is used by Replication Server.
239               */
240               begin transaction rs_logexec
241   
242               /*
243               **  Go ahead and change the partition name.
244               */
245               update syspartitions
246               set name = @newname
247               from syspartitions
248               where id = @objid
249                   and indid = @indid
250                   and partitionid = @ptnid
251   
252               /*
253               ** We updated a syspartition row. We also need to update the
254               ** in-core structure representing this syspartition row as the
255               ** syspartition rows cache is not a write thru cache.
256               */
257               dbcc refreshpdes(@dbid, @objid, @indid, @ptnid)
258   
259               /*
260               ** If there was a error in rollback the update to syspartitions.
261               ** dbcc refreshides would have printed the error message.
262               */
263               if @@error != 0
264               begin
265                   rollback transaction rs_logexec
266                   return (1)
267               end
268   
269               /*
270               ** Write the log record to replicate this invocation
271               ** of the stored procedure.
272               */
273               if (logexec() != 1)
274               begin
275                   /*
276                   ** 17756, "The execution of the stored procedure '%1!'
277                   **         in database '%2!' was aborted because there
278                   **         was an error in writing the replication log
279                   **         record."
280                   */
281                   select @dbname = db_name()
282                   raiserror 17756, "sp_rename", @dbname
283   
284                   rollback transaction rs_logexec
285                   return (1)
286               end
287   
288               commit transaction
289               /*
290               ** 17162, "Partition name has been changed."
291               */
292               exec sp_getmessage 17162, @msg output
293               print @msg
294               return (0)
295           end
296       end
297   
298       /*
299       **  Check to see if we are renaming a table/column (or table/index)
300       **  or a table or usertype.
301       **  If @objname is of the form table.column then it's a column.
302       **  In the column case, we need to extract and verify the table and
303       **  column names and make sure the user owns the table in which the
304       **  column is being renamed.
305       */
306       if @objname like "%.%"
307       begin
308           /*
309           **  Get the table name out.
310           */
311           select @tabname = substring(@objname, 1, charindex(".", @objname) - 1)
312           select @colname = substring(@objname, charindex(".", @objname) + 1, @maxtotlen)
313   
314           set @tabobjid = object_id(@tabname)
315           if (@tabobjid IS NULL)
316           begin
317               raiserror 18228, @tabname
318               return (1)
319           end
320   
321           /*
322           **  If no third parameter was specified, or, if third parameter
323           **  was specified as 'index', see if there is an index
324           **  of this name in a table owned by the user, and keep it in a 
325           **  local variable.
326           */
327           if (@indorcolorpar is null or @indorcolorpar = 'index')
328           begin
329               select @index_objid = i.id, @indid = i.indid
330               from sysobjects o, sysindexes i
331               where o.id = @tabobjid
332                   and o.id = i.id
333                   and i.name = @colname
334                   and i.indid != 0
335                   and o.sysstat & 7 = 3 /* user table */
336           end
337   
338   
339           /*
340           **  If no third parameter was specified, or, if third parameter
341           **  was specified as 'partition', see if there is a partition
342           **  of this name in a table owned by the user, and keep it in a
343           **  local variable.
344           */
345           if (@indorcolorpar is null or @indorcolorpar = 'partition')
346           begin
347               select @partition_objid = p.id,
348                   @indid = p.indid,
349                   @ptnid = p.partitionid
350               from sysobjects o, syspartitions p
351               where p.id = o.id
352                   and o.id = @tabobjid
353                   and o.sysstat & 7 = 3 /* user table */
354                   and p.name = @colname
355           end
356   
357           /*
358           **  Now check to see that the column exists in a table owned
359           **  by the user. Don't do this if the user explicitly specified
360           **  that this is an index or partition.
361           */
362           if (@indorcolorpar is null or (@indorcolorpar not in ('index', 'partition')))
363           begin
364               select @objid = o.id, @colid = c.colid
365               from sysobjects o, syscolumns c
366               where c.id = @tabobjid
367                   and c.id = o.id
368                   and c.name = @colname
369                   and (o.sysstat & 7 = 2 /* user table */
370                       or o.sysstat & 7 = 3) /* view */
371           end
372   
373           /*
374           **  Did we find it?  If not, it might be an index name so we'll
375           **  check in the next case. If the user explicitly specified 
376           **  that this is an index name, check in the next case as well.
377           */
378           if @objid is not null
379           begin
380               /*
381               **  If there is an index as well as a column of the same
382               **  name, raise an error to warn the user of this ambiguity.
383               */
384               if @index_objid is not null
385               begin
386                   /*
387                   ** 18939, "There is an ambiguity with the object named '%1!'. Please use 
388                   ** the third argument to specify whether you are renaming a '%2!' or 
389                   ** '%3!'.
390                   */
391                   raiserror 18939, @colname, "column", "index"
392                   return (1)
393               end
394   
395               /*
396               **  If there is an partition as well as a column of the same
397               **  name, raise an error to warn the user of this ambiguity.
398               */
399               if @partition_objid is not null
400               begin
401                   /*
402                   ** 18939, "There is an ambiguity with the object named '%1!'. Please use 
403                   ** the third argument to specify whether you are renaming a '%2!' or 
404                   ** '%3!'.
405                   */
406                   raiserror 18939, @colname, "partition", "column"
407                   return (1)
408               end
409   
410   
411               /* 
412               ** Cannot modify the name of a function-based index key. 
413               ** The name is a system name created internally.
414               */
415               if exists (select 1
416                       from syscolumns
417                       where id = @objid and
418                           colid = @colid and
419                           status3 & 1 = 1)
420               begin
421                   /*
422                   ** 17786, "Object name cannot be changed either 
423                   ** because it does not exist in this database, 
424                   ** or you don't own it, or it is a system name."
425                   */
426                   raiserror 17786
427                   return (1)
428               end
429   
430               /*
431               **  Check to make sure that there is no already a column
432               **  that has the new name.
433               */
434               if exists (select *
435                       from syscolumns
436                       where id = @objid
437                           and name = @newname)
438               begin
439                   /*
440                   ** 17780, "There is already a column named '%1!' in table '%2!'."
441                   */
442                   raiserror 17780, @newname, @tabname
443                   return (1)
444               end
445   
446               /* determine the object's replication status */
447   
448               /* Replication enabled flag is 8000H (which is -32768D) */
449               select @rep_constant = - 32768
450   
451               select
452                   @cur_sysstat = sysstat
453               from
454                   sysobjects holdlock
455               where
456                   id = @objid
457   
458               if (@cur_sysstat & @rep_constant) = @rep_constant
459               begin
460                   select @rep_obj = 1
461               end
462               else
463               begin
464                   select @rep_obj = 0
465               end
466   
467               /* determine the database's replication status */
468               select @rep_db_stat = getdbrepstat()
469               if (@rep_db_stat = @lt_rep_get_failed)
470               begin
471                   /*
472                   ** 18409, "The built-in function getdbrepstat() 
473                   ** failed. Please see the other messages printed 
474                   ** along with this message."
475                   */
476                   raiserror 18409, "getdbrepstat"
477                   return (1)
478               end
479               else
480               begin
481                   if ((@rep_db_stat & @lt_rep_all = @lt_rep_all) or
482                           (@rep_db_stat & @lt_rep_l1 = @lt_rep_l1))
483                       select @rep_db = 1
484                   else
485                       select @rep_db = 0
486               end
487   
488               /*
489               ** IMPORTANT: The name rs_logexec is significant
490               ** and is used by Replication Server. 
491               */
492               begin transaction rs_logexec
493   
494               /* if the object is replicated, log the schema before 
495               ** changing the column name
496               */
497               if ((@rep_obj = 1) or (@rep_db = 1))
498               begin
499                   select @user_tran = 0
500                   select @after_image = 0
501                   select @mod_versionts = 1
502                   if (logschema(@objid, @user_tran, @after_image,
503                               @mod_versionts) != 1)
504                   begin
505                       /*
506                       ** 17968 "The built-in function logschema() 
507                       ** failed for '%1!'."
508                       */
509                       raiserror 17968, @tabname
510   
511                       rollback transaction rs_logexec
512                       return (1)
513                   end
514               end
515   
516               /*
517               ** Update schema count for this table or view.
518               */
519               if (schema_inc(object_id(@tabname), 2) != 1)
520               begin
521                   /*
522                   ** 17763, "The execution of the stored procedure '%1!'
523                   **         in database '%2!' was aborted because there
524                   **         was an error in updating the column
525                   **         schemacnt in sysobjects."
526                   */
527                   select @dbname = db_name()
528                   raiserror 17763, "sp_rename", @dbname
529                   rollback transaction rs_logexec
530                   return (1)
531               end
532   
533               /*
534               **  Go ahead and change the column name.
535               */
536               update syscolumns
537               set name = @newname
538               from syscolumns
539               where id = @objid
540                   and colid = @colid
541               /*
542               ** If we are renaming the SYB_IDENTITY_COL
543               ** then turn off the COL_AUTO_IDENTITY bit (0x2).
544               ** Note that we can never rename a column to
545               ** SYB_IDENTIY_COL (since valid_name() will fail)
546               ** so don't worry about the converse.
547               */
548               if (@colname = "SYB_IDENTITY_COL")
549               begin
550                   update syscolumns
551                   set status = (~ 2 & status)
552                   from syscolumns
553                   where id = @objid
554                       and colid = @colid
555               end
556   
557               /*
558               ** Write the log record to replicate this invocation 
559               ** of the stored procedure.
560               */
561               if (logexec() != 1)
562               begin
563                   /*
564                   ** 17756, "The execution of the stored procedure '%1!'
565                   ** 	   in database '%2!' was aborted because there
566                   ** 	   was an error in writing the replication log
567                   **	   record."
568                   */
569                   select @dbname = db_name()
570                   raiserror 17756, "sp_rename", @dbname
571   
572                   rollback transaction rs_logexec
573                   return (1)
574               end
575   
576               /* commit the transaction */
577               commit transaction
578   
579               /*
580               ** 17781, "Column name has been changed."
581               */
582               exec sp_getmessage 17781, @msg output
583               print @msg
584               /*
585               ** 19819  "Warning: Changing an object or column name may 
586               ** break existing stored procedures, cached statements or 
587               ** other compiled objects."
588               */
589               exec sp_getmessage 19819, @msg output
590               print @msg
591               return (0)
592           end
593   
594           /*
595           **  Might be an index name.
596           */
597           else if @index_objid is not null
598           begin
599               /*
600               **  We have already obtained the objid from sysindexes.
601               */
602               select @objid = @index_objid
603   
604               /*
605               **  If there is an partition as well as a index of the same
606               **  name, raise an error to warn the user of this ambiguity.
607               */
608               if @partition_objid is not null
609               begin
610                   /*
611                   ** 18939, "There is an ambiguity with the object named '%1!'. Please use 
612                   ** the third argument to specify whether you are renaming a '%2!' or 
613                   ** '%3!'.
614                   */
615                   raiserror 18939, @colname, "partition", "index"
616                   return (1)
617               end
618   
619               /*
620               **  Check to make sure that there is no already an index
621               **  that has the new name.
622               */
623               if exists (select *
624                       from sysindexes
625                       where id = @objid
626                           and name = @newname
627                           and indid > 0)
628               begin
629                   /*
630                   ** 17783, "There is already an index named '%1!' for table '%2!'."
631                   */
632                   raiserror 17783, @newname, @tabname
633                   return (1)
634               end
635   
636               /*
637               ** IMPORTANT: The name rs_logexec is significant
638               ** and is used by Replication Server. 
639               */
640               begin transaction rs_logexec
641   
642               /*
643               **  Go ahead and change the index name.
644               **  Clear status2 bit 0x8 since the index name is provided by user.
645               */
646               update sysindexes
647               set name = @newname, status2 = (~ 8 & status2)
648               from sysindexes
649               where id = @objid and indid = @indid
650               plan "(update (i_scan csysindexes sysindexes))"
651   
652               /*
653               ** We updated a sysindexes row. We also need to update the
654               ** in-core structure representing this sysindexes row as the
655               ** sysindexes rows cache is not a write thru cache. 
656               */
657               dbcc refreshides(@dbid, @objid, @indid, "indname")
658   
659               /* 
660               ** If there was a error in rollback the update to sysindexes.
661               ** dbcc refreshides would have printed the error message.
662               */
663               if @@error != 0
664               begin
665                   rollback transaction rs_logexec
666                   return (1)
667               end
668   
669               /*
670               ** Write the log record to replicate this invocation 
671               ** of the stored procedure.
672               */
673               if (logexec() != 1)
674               begin
675                   /*
676                   ** 17756, "The execution of the stored procedure '%1!'
677                   ** 	   in database '%2!' was aborted because there
678                   ** 	   was an error in writing the replication log
679                   **	   record."
680                   */
681                   select @dbname = db_name()
682                   raiserror 17756, "sp_rename", @dbname
683   
684                   rollback transaction rs_logexec
685                   return (1)
686               end
687   
688               commit transaction
689               /*
690               ** 17784, "Index name has been changed."
691               */
692               exec sp_getmessage 17784, @msg output
693               print @msg
694               return (0)
695           end
696           /*
697           **  Might be a partition name.
698           */
699           else if @partition_objid is not null
700           begin
701               /*
702               **  We have already obtained the objid from syspartitions.
703               */
704               select @objid = @partition_objid
705   
706               /*
707               **  Check to make sure that there is no already a partition
708               **  that has the new name.
709               */
710               if exists (select *
711                       from syspartitions
712                       where id = @objid
713                           and indid = @indid
714                           and name = @newname)
715               begin
716                   /*
717                   ** 17783, "There is already a partition named '%1!' for table '%2!'."
718                   */
719                   raiserror 17783, @newname, @tabname
720                   return (1)
721               end
722   
723               /*
724               ** IMPORTANT: The name rs_logexec is significant
725               ** and is used by Replication Server.
726               */
727               begin transaction rs_logexec
728   
729               /*
730               **  Go ahead and change the partition name.
731               */
732               update syspartitions
733               set name = @newname
734               from syspartitions
735               where id = @objid
736                   and indid = @indid
737                   and partitionid = @ptnid
738   
739               set @error = @@error, @rowcount = @@rowcount
740   
741               /* Only one row should be affected */
742               if ((@error != 0) or (@rowcount != 1))
743               begin
744                   if ((@error = 0) and (@rowcount != 1))
745                       raiserror 19379, "syspartitions", @rowcount, "1"
746   
747                   rollback transaction rs_logexec
748                   return (1)
749               end
750   
751               /*
752               ** We updated a syspartitions row. We also need to update the
753               ** in-core structure representing this syspartitions row.
754               */
755               dbcc refreshpdes(@dbid, @objid, @indid, @ptnid)
756   
757               /*
758               ** If there was a error in rollback the update to syspartitions.
759               ** dbcc refreshides would have printed the error message.
760               */
761               if @@error != 0
762               begin
763                   rollback transaction rs_logexec
764                   return (1)
765               end
766   
767               /*
768               ** Write the log record to replicate this invocation
769               ** of the stored procedure.
770               */
771               if (logexec() != 1)
772               begin
773                   /*
774                   ** 17756, "The execution of the stored procedure '%1!'
775                   **         in database '%2!' was aborted because there
776                   **         was an error in writing the replication log
777                   **         record."
778                   */
779                   select @dbname = db_name()
780                   raiserror 17756, "sp_rename", @dbname
781   
782                   rollback transaction rs_logexec
783                   return (1)
784               end
785   
786               commit transaction
787   
788               /*
789               ** 17162, "Partition name has been changed."
790               */
791               exec sp_getmessage 17162, @msg output
792               print @msg
793               return (0)
794           end
795           else
796           begin
797               /*
798               **  If all 3 are now NULL then it means that the 2nd part-name
799               ** is not an index / partition / column name.
800               **
801               ** 17782, "You do not own a table, column, index or
802               ** partition of that name in the current database."
803               */
804               raiserror 17782
805               return (1)
806           end
807       end
808   
809       /*
810       **  Check to see if the object exists and is owned by the user.
811       **  It will either be in the sysobjects table or the systypes table.
812       **  Check sysobjects first.
813       **  System objects have ids < 100 and we don't allow their names to change.
814       */
815       if exists (select id
816               from sysobjects
817               where id = object_id(@objname)
818                   and uid = user_id()
819                   and id > 99)
820       /*
821       **  Don't allow the newname to begin with #.
822       */
823       begin
824           if substring(@newname, 1, 1) = "#"
825           begin
826               /*
827               ** 17785, "Table or view names beginning with '#' are not allowed."
828               */
829               raiserror 17785
830               return (1)
831           end
832       end
833   
834       /*
835       **  It's not in sysobjects so check systypes.
836       */
837       else
838       begin
839           select @objid = usertype
840           from systypes
841           where name = @objname
842               and uid = user_id()
843               and usertype > 99
844   
845           /*
846           **  It's nowhere to be found so quit.
847           */
848           if @objid is NULL
849           begin
850               /*
851               ** 17786, "Object name cannot be changed either because it does not exist in this database, or you don't own it, or it is a system name."
852               */
853               raiserror 17786
854               return (1)
855           end
856   
857           /* Check that newname doesn't already exist. */
858           if exists (select *
859                   from systypes
860                   where name = @newname)
861           begin
862               /*
863               ** 17787, "Newname already exists in systypes."
864               */
865               raiserror 17787
866               return (1)
867           end
868   
869           /*
870           ** IMPORTANT: This transaction name is significant and is used by
871           **            Replication Server
872           */
873           begin transaction rs_logexec
874   
875           /*
876           ** Change the name of a datatype
877           */
878           update systypes
879           set name = @newname
880           where usertype = @objid
881   
882           /*
883           ** Write the log record to replicate this invocation 
884           ** of the stored procedure.
885           */
886           if (logexec() != 1)
887           begin
888               /*
889               ** 17756, "The execution of the stored procedure '%1!'
890               ** 	   in database '%2!' was aborted because there
891               ** 	   was an error in writing the replication log
892               **	   record."
893               */
894               select @dbname = db_name()
895               raiserror 17756, "sp_setreptable", @dbname
896   
897               rollback transaction rs_logexec
898               return (1)
899           end
900           commit transaction
901   
902           /*
903           ** 18058, "Name of user-defined type name changed."
904           */
905           exec sp_getmessage 18058, @msg output
906           print @msg
907           return (0)
908       end
909   
910       /*
911       **  It might be a table so update the index entry for the table IF it has
912       **  no clustered index.  No clustered index means that there is an entry
913       **  for the table under the @objid with indid = 0.
914       */
915   
916       /* Check that newname doesn't already exist. */
917       if exists (select *
918               from sysobjects
919               where name = @newname
920                   and uid = user_id())
921       begin
922           /*
923           ** 17788, "Newname already exists in sysobjects."
924           */
925           raiserror 17788
926           return (1)
927       end
928   
929       /*
930       ** IMPORTANT: This transaction name is significant and is used by
931       **            Replication Server
932       */
933       begin transaction rs_logexec
934   
935       /* if the object is a table or a procedure, we may have to log its
936       ** schema before/after changing its name
937       */
938       if exists (
939               select id
940               from sysobjects where
941                   (type = "U" or type = "P" or type = "WS") and
942                   name = @objname
943               )
944       begin
945           select @table_or_proc = 1
946       end
947       else
948       begin
949           select @table_or_proc = 0
950       end
951   
952       /* 
953       ** Is the object a service?
954       */
955   
956       if exists (
957               select id
958               from sysobjects where
959                   type = "WS" and
960                   name = @objname
961               )
962       begin
963           /*
964           ** Lock the specific row in the sysattributes table to 
965           ** avoid race conditions with sp_webservices deploy and
966           ** undeploy.
967           */
968   
969           select @temp_objid = object from sysattributes holdlock where
970               class = 18 and
971               attribute = 6 and
972               object = object_id(@objname)
973   
974           /*
975           ** If the service is deployed do not allow the rename 
976           ** to go through. 
977           */
978   
979           if exists (
980                   select object_info3 from sysattributes where
981                       object = object_id(@objname) and
982                       class = 18 and
983                       attribute = 6 and
984                       object_info3 & 128 = 128
985                   )
986           begin
987               /*
988               ** 19412, "Cannot rename a service that is deployed. "
989               */
990   
991               raiserror 19412
992               rollback transaction rs_logexec
993               return (1)
994           end
995       end
996   
997       /* determine the object's replication status if it is a table or
998       ** a procedure and log its schema if necessary
999       */
1000      if (@table_or_proc = 1)
1001      begin
1002  
1003          /* Replication enabled flag is 8000H (which is -32768D) */
1004          select @rep_constant = - 32768
1005  
1006          select
1007              @cur_sysstat = sysstat
1008          from
1009              sysobjects holdlock
1010          where
1011              id = object_id(@objname)
1012  
1013          if (@cur_sysstat & @rep_constant) = @rep_constant
1014          begin
1015              select @rep_obj = 1
1016          end
1017          else
1018          begin
1019              select @rep_obj = 0
1020          end
1021  
1022          /* check if db is replicated */
1023          select @rep_db_stat = getdbrepstat()
1024          if (@rep_db_stat = @lt_rep_get_failed)
1025          begin
1026              /*
1027              ** 18409, "The built-in function getdbrepstat() 
1028              ** failed. Please see the other messages printed 
1029              ** along with this message."
1030              */
1031              raiserror 18409
1032              rollback transaction rs_logexec
1033              return (1)
1034          end
1035          else
1036          begin
1037              if ((@rep_db_stat & @lt_rep_all = @lt_rep_all) or
1038                      (@rep_db_stat & @lt_rep_l1 = @lt_rep_l1))
1039                  select @rep_db = 1
1040              else
1041                  select @rep_db = 0
1042          end
1043  
1044          /*
1045          ** if db is replicated, and object is user table, then the
1046          ** user table is replicated even if it is not explicitly
1047          ** marked for replication
1048          */
1049          if ((@rep_obj = 0) and (@rep_db = 1))
1050          begin
1051              if exists (
1052                      select id from
1053                          sysobjects where
1054                          (type = "U") and
1055                          (id = object_id(@objname))
1056                      )
1057              begin
1058                  select @rep_obj = 1
1059              end
1060          end
1061  
1062          if (@rep_obj = 1)
1063          begin
1064              select @user_tran = 0
1065              select @after_image = 0
1066              select @mod_versionts = 1
1067              if (logschema(object_id(@objname), @user_tran,
1068                          @after_image, @mod_versionts) != 1)
1069              begin
1070                  /*
1071                  ** 17968 "The built-in function logschema() 
1072                  ** failed for '%1!'."
1073                  */
1074                  raiserror 17968, @objname
1075  
1076                  rollback transaction rs_logexec
1077                  return (1)
1078              end
1079          end
1080      end
1081  
1082      /*
1083      ** Update schema count for this table or view.
1084      */
1085      select @obj_type = type
1086      from sysobjects where id = object_id(@objname)
1087  
1088      if (@obj_type = 'U' or @obj_type = 'V')
1089      begin
1090          if (schema_inc(object_id(@objname), 2) != 1)
1091          begin
1092              /*
1093              ** 17763, "The execution of the stored procedure '%1!'
1094              **         in database '%2!' was aborted because there
1095              **         was an error in updating the column
1096              **         schemacnt in sysobjects."
1097              */
1098              select @dbname = db_name()
1099              raiserror 17763, "sp_rename", @dbname
1100              rollback transaction rs_logexec
1101              return (1)
1102          end
1103      end
1104  
1105      update sysobjects
1106      set name = @newname
1107      where id = object_id(@objname)
1108  
1109      /*
1110      ** If the object is a proxy table, update sysattributes
1111      */
1112      update sysattributes
1113      set object_cinfo = @newname
1114      where object_cinfo = @objname and class = 9
1115  
1116      /*
1117      **  This might not do anything -- only if we are dealing with a
1118      **  table that has no clustered index.
1119      **  Also change the name of the text entry, if any.
1120      */
1121      update sysindexes
1122      set name = @newname
1123      where id = object_id(@objname) and indid = 0
1124      plan "(update (i_scan csysindexes sysindexes))"
1125  
1126      /*
1127      ** We updated a sysindexes row. We also need to update the
1128      ** in-core structure representing this sysindexes row as the
1129      ** sysindexes rows cache is not a write thru cache. 
1130      */
1131      select @temp_dbid = db_id()
1132      select @temp_objid = object_id(@objname)
1133  
1134      dbcc refreshides(@temp_dbid, @temp_objid, 0, "indname")
1135  
1136      /* dbcc refreshides would print a message in case of error */
1137      if @@error != 0
1138      begin
1139          rollback transaction rs_logexec
1140          return (1)
1141      end
1142  
1143      update sysindexes
1144      set name = "t" + @newname
1145      where id = object_id(@objname) and indid = 255
1146      plan "(update (i_scan csysindexes sysindexes))"
1147  
1148      /*
1149      ** We updated a sysindexes row. We also need to update the
1150      ** in-core structure representing this sysindexes row as the
1151      ** sysindexes rows cache is not a write thru cache. 
1152      */
1153      dbcc refreshides(@temp_dbid, @temp_objid, 255, "indname")
1154  
1155      /* dbcc refreshides would print a message in case of error */
1156      if @@error != 0
1157      begin
1158          rollback transaction rs_logexec
1159          return (1)
1160      end
1161  
1162      /*
1163      **	We also must update the object name in the descriptor
1164      **	otherwise, in the cache, the object would be under the
1165      **	old name.
1166      */
1167      dbcc chgobjname(@objname, @newname)
1168  
1169      if @@error != 0
1170      begin
1171          rollback transaction rs_logexec
1172          return (1)
1173      end
1174  
1175      /*
1176      ** Write the log record to replicate this invocation 
1177      ** of the stored procedure.
1178      */
1179      if (logexec() != 1)
1180      begin
1181          /*
1182          ** 17756, "The execution of the stored procedure '%1!'
1183          ** 	   in database '%2!' was aborted because there
1184          ** 	   was an error in writing the replication log
1185          **	   record."
1186          */
1187          select @dbname = db_name()
1188          raiserror 17756, "sp_rename", @dbname
1189  
1190          rollback transaction rs_logexec
1191          return (1)
1192      end
1193  
1194      commit transaction
1195  
1196      /*
1197      ** 17789, "Object name has been changed."
1198      */
1199      exec sp_getmessage 17789, @msg output
1200      print @msg
1201  
1202      /*
1203      ** 19819  "Warning: Changing an object or column name may break existing stored procedures, cached statements or other compiled objects."
1204      */
1205      exec sp_getmessage 19819, @msg output
1206      print @msg
1207  
1208      return (0)
1209  


exec sp_procxmode 'sp_rename', 'AnyMode'
go

Grant Execute on sp_rename to public
go
DEFECTS
 MCTR 4 Conditional Begin Tran or Commit Tran 240
 MCTR 4 Conditional Begin Tran or Commit Tran 288
 MCTR 4 Conditional Begin Tran or Commit Tran 492
 MCTR 4 Conditional Begin Tran or Commit Tran 577
 MCTR 4 Conditional Begin Tran or Commit Tran 640
 MCTR 4 Conditional Begin Tran or Commit Tran 688
 MCTR 4 Conditional Begin Tran or Commit Tran 727
 MCTR 4 Conditional Begin Tran or Commit Tran 786
 MCTR 4 Conditional Begin Tran or Commit Tran 873
 MCTR 4 Conditional Begin Tran or Commit Tran 900
 MINU 4 Unique Index with nullable columns sybsystemprocs..sysattributes sybsystemprocs..sysattributes
 MTYP 4 Assignment type mismatch name: varchar(255) = varchar(256) 246
 MTYP 4 Assignment type mismatch name: longsysname(255) = varchar(256) 537
 MTYP 4 Assignment type mismatch name: longsysname(255) = varchar(256) 647
 MTYP 4 Assignment type mismatch name: varchar(255) = varchar(256) 733
 MTYP 4 Assignment type mismatch name: longsysname(255) = varchar(256) 879
 MTYP 4 Assignment type mismatch name: longsysname(255) = varchar(256) 1106
 MTYP 4 Assignment type mismatch object_cinfo: varchar(255) = varchar(256) 1113
 MTYP 4 Assignment type mismatch name: longsysname(255) = varchar(256) 1122
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: sysindexes.csysindexes unique clustered
(id, indid)
Intersection: {indid}
193
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: syspartitions.nc2syspartitions unique
(id, indid, name)
Intersection: {name}
195
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: sysindexes.csysindexes unique clustered
(id, indid)
Intersection: {indid}
333
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: syspartitions.nc2syspartitions unique
(id, indid, name)
Intersection: {name}
354
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 194
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 226
 QTYP 4 Comparison type mismatch smallint = int 226
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 249
 QTYP 4 Comparison type mismatch smallint = int 249
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 334
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 418
 QTYP 4 Comparison type mismatch smallint = int 418
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 540
 QTYP 4 Comparison type mismatch smallint = int 540
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 554
 QTYP 4 Comparison type mismatch smallint = int 554
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 627
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 649
 QTYP 4 Comparison type mismatch smallint = int 649
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 713
 QTYP 4 Comparison type mismatch smallint = int 713
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 736
 QTYP 4 Comparison type mismatch smallint = int 736
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 843
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 880
 QTYP 4 Comparison type mismatch smallint = int 880
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 970
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 971
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 982
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 983
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 1114
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 1123
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 1145
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 95
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 98
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 186
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 196
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 196
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 197
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 197
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 225
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 248
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 329
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 331
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 332
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 332
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 347
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 351
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 351
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 352
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 364
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 366
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 367
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 367
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 417
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 436
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 456
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 539
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 553
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 625
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 649
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 712
 MAW1 3 Warning message on %name% sybsystemprocs..syspartitions.id: Warning message on syspartitions 735
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 815
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 817
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 819
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 939
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 957
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 1011
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 1052
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 1055
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 1086
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 1107
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 1123
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 1145
 MGTP 3 Grant to public sybsystemprocs..sp_rename  
 MGTP 3 Grant to public sybsystemprocs..sysattributes  
 MGTP 3 Grant to public sybsystemprocs..syscolumns  
 MGTP 3 Grant to public sybsystemprocs..sysindexes  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MGTP 3 Grant to public sybsystemprocs..syspartitions  
 MGTP 3 Grant to public sybsystemprocs..systypes  
 MNAC 3 Not using ANSI 'is null' 175
 MNER 3 No Error Check should check @@error after update 245
 MNER 3 No Error Check should check return value of exec 292
 MNER 3 No Error Check should check @@error after update 536
 MNER 3 No Error Check should check @@error after update 550
 MNER 3 No Error Check should check return value of exec 582
 MNER 3 No Error Check should check return value of exec 589
 MNER 3 No Error Check should check @@error after update 646
 MNER 3 No Error Check should check return value of exec 692
 MNER 3 No Error Check should check return value of exec 791
 MNER 3 No Error Check should check @@error after update 878
 MNER 3 No Error Check should check return value of exec 905
 MNER 3 No Error Check should check @@error after update 1105
 MNER 3 No Error Check should check @@error after update 1112
 MNER 3 No Error Check should check @@error after update 1121
 MNER 3 No Error Check should check @@error after update 1143
 MNER 3 No Error Check should check return value of exec 1199
 MNER 3 No Error Check should check return value of exec 1205
 MUCO 3 Useless Code Useless Brackets 79
 MUCO 3 Useless Code Useless Brackets 104
 MUCO 3 Useless Code Useless Brackets 118
 MUCO 3 Useless Code Useless Brackets 127
 MUCO 3 Useless Code Useless Brackets 129
 MUCO 3 Useless Code Useless Brackets 137
 MUCO 3 Useless Code Useless Brackets 149
 MUCO 3 Useless Code Useless Brackets 167
 MUCO 3 Useless Code Useless Brackets 171
 MUCO 3 Useless Code Useless Brackets 175
 MUCO 3 Useless Code Useless Brackets 216
 MUCO 3 Useless Code Useless Brackets 233
 MUCO 3 Useless Code Useless Brackets 266
 MUCO 3 Useless Code Useless Brackets 273
 MUCO 3 Useless Code Useless Brackets 285
 MUCO 3 Useless Code Useless Brackets 294
 MUCO 3 Useless Code Useless Brackets 315
 MUCO 3 Useless Code Useless Brackets 318
 MUCO 3 Useless Code Useless Brackets 327
 MUCO 3 Useless Code Useless Brackets 345
 MUCO 3 Useless Code Useless Brackets 362
 MUCO 3 Useless Code Useless Brackets 392
 MUCO 3 Useless Code Useless Brackets 407
 MUCO 3 Useless Code Useless Brackets 427
 MUCO 3 Useless Code Useless Brackets 443
 MUCO 3 Useless Code Useless Brackets 469
 MUCO 3 Useless Code Useless Brackets 477
 MUCO 3 Useless Code Useless Brackets 481
 MUCO 3 Useless Code Useless Brackets 497
 MUCO 3 Useless Code Useless Brackets 502
 MUCO 3 Useless Code Useless Brackets 512
 MUCO 3 Useless Code Useless Brackets 519
 MUCO 3 Useless Code Useless Brackets 530
 MUCO 3 Useless Code Useless Brackets 548
 MUCO 3 Useless Code Useless Brackets 561
 MUCO 3 Useless Code Useless Brackets 573
 MUCO 3 Useless Code Useless Brackets 591
 MUCO 3 Useless Code Useless Brackets 616
 MUCO 3 Useless Code Useless Brackets 633
 MUCO 3 Useless Code Useless Brackets 666
 MUCO 3 Useless Code Useless Brackets 673
 MUCO 3 Useless Code Useless Brackets 685
 MUCO 3 Useless Code Useless Brackets 694
 MUCO 3 Useless Code Useless Brackets 720
 MUCO 3 Useless Code Useless Brackets 742
 MUCO 3 Useless Code Useless Brackets 744
 MUCO 3 Useless Code Useless Brackets 748
 MUCO 3 Useless Code Useless Brackets 764
 MUCO 3 Useless Code Useless Brackets 771
 MUCO 3 Useless Code Useless Brackets 783
 MUCO 3 Useless Code Useless Brackets 793
 MUCO 3 Useless Code Useless Brackets 805
 MUCO 3 Useless Code Useless Brackets 830
 MUCO 3 Useless Code Useless Brackets 854
 MUCO 3 Useless Code Useless Brackets 866
 MUCO 3 Useless Code Useless Brackets 886
 MUCO 3 Useless Code Useless Brackets 898
 MUCO 3 Useless Code Useless Brackets 907
 MUCO 3 Useless Code Useless Brackets 926
 MUCO 3 Useless Code Useless Brackets 993
 MUCO 3 Useless Code Useless Brackets 1000
 MUCO 3 Useless Code Useless Brackets 1024
 MUCO 3 Useless Code Useless Brackets 1033
 MUCO 3 Useless Code Useless Brackets 1037
 MUCO 3 Useless Code Useless Brackets 1049
 MUCO 3 Useless Code Useless Brackets 1062
 MUCO 3 Useless Code Useless Brackets 1067
 MUCO 3 Useless Code Useless Brackets 1077
 MUCO 3 Useless Code Useless Brackets 1088
 MUCO 3 Useless Code Useless Brackets 1090
 MUCO 3 Useless Code Useless Brackets 1101
 MUCO 3 Useless Code Useless Brackets 1140
 MUCO 3 Useless Code Useless Brackets 1159
 MUCO 3 Useless Code Useless Brackets 1172
 MUCO 3 Useless Code Useless Brackets 1179
 MUCO 3 Useless Code Useless Brackets 1191
 MUCO 3 Useless Code Useless Brackets 1208
 MUPK 3 Update column which is part of a PK or unique index name 246
 MUPK 3 Update column which is part of a PK or unique index name 733
 MUPK 3 Update column which is part of a PK or unique index name 879
 MUPK 3 Update column which is part of a PK or unique index name 1106
 MUPK 3 Update column which is part of a PK or unique index object_cinfo 1113
 MUUF 3 Update or Delete with Useless From Clause 245
 MUUF 3 Update or Delete with Useless From Clause 536
 MUUF 3 Update or Delete with Useless From Clause 550
 MUUF 3 Update or Delete with Useless From Clause 646
 MUUF 3 Update or Delete with Useless From Clause 732
 QAFM 3 Var Assignment from potentially many rows 94
 QAFM 3 Var Assignment from potentially many rows 97
 QAFM 3 Var Assignment from potentially many rows 364
 QAFM 3 Var Assignment from potentially many rows 969
 QFAP 3 Force abstract plan ABSTRACT_PLAN_CLAUSE plan..."(update (i_scan csysindexes sysindexes))" 646
 QFAP 3 Force abstract plan ABSTRACT_PLAN_CLAUSE plan..."(update (i_scan csysindexes sysindexes))" 1121
 QFAP 3 Force abstract plan ABSTRACT_PLAN_CLAUSE plan..."(update (i_scan csysindexes sysindexes))" 1143
 QISO 3 Set isolation level 157
 QNAJ 3 Not using ANSI Inner Join 189
 QNAJ 3 Not using ANSI Inner Join 330
 QNAJ 3 Not using ANSI Inner Join 350
 QNAJ 3 Not using ANSI Inner Join 365
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
95
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
98
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
366
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {colid, id}
417
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
436
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {colid, id}
539
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {colid, id}
553
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysobjects.ncsysobjects unique
(name, uid)
Intersection: {name}
941
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysobjects.ncsysobjects unique
(name, uid)
Intersection: {name}
959
 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}
970
 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, object_info3, attribute, class}
981
 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: {class, object_cinfo}
1114
 VUNU 3 Variable is not used @curdb_name 31
 MSUB 2 Subquery Marker 223
 MSUB 2 Subquery Marker 415
 MSUB 2 Subquery Marker 434
 MSUB 2 Subquery Marker 623
 MSUB 2 Subquery Marker 710
 MSUB 2 Subquery Marker 815
 MSUB 2 Subquery Marker 858
 MSUB 2 Subquery Marker 917
 MSUB 2 Subquery Marker 938
 MSUB 2 Subquery Marker 956
 MSUB 2 Subquery Marker 979
 MSUB 2 Subquery Marker 1051
 MTR1 2 Metrics: Comments Ratio Comments: 47% 18
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 78 = 123dec - 47exi + 2 18
 MTR3 2 Metrics: Query Complexity Complexity: 483 18
 PRED_QUERY_COLLECTION 2 {i=sybsystemprocs..sysindexes, o=sybsystemprocs..sysobjects, p=sybsystemprocs..syspartitions} 0 186
 PRED_QUERY_COLLECTION 2 {i=sybsystemprocs..sysindexes, o=sybsystemprocs..sysobjects} 0 329
 PRED_QUERY_COLLECTION 2 {o=sybsystemprocs..sysobjects, p=sybsystemprocs..syspartitions} 0 347
 PRED_QUERY_COLLECTION 2 {c=sybsystemprocs..syscolumns, o=sybsystemprocs..sysobjects} 0 364

DATA PROPAGATION detailed
ColumnWritten To
@newnamesysattributes.object_cinfo   syscolumns.name   syscomments.text   sysindexes.name   sysobjects.name   syspartitions.name   systypes.name   sp_cachestrategy_rset_001.index name sp_checknames_rset_001.dbid sp_checknames_rset_003.name
sp_checknames_rset_004.dbname sp_checknames_rset_005.suid °.name sp_checkreswords_rset_014.Reserved Word Language Names sp_checkreswords_rset_016.Reserved Word Remote Logins sp_checkreswords_rset_017.Reserved Word Server Names sp_columns_rset_001.table_name °.column_name sp_columns_rset_002.table_name °.column_name
sp_datatype_info_rset_001.type_name sp_datatype_info_rset_002.type_name sp_dropalias_rset_002.Segment name sp_dropgroup_rset_002.name sp_droptype_rset_001.object °.column °.datatype sp_dropuser_rset_003.grantor sp_dropuser_rset_004.Segment name sp_helpconstraint_rset_001.name
sp_helpconstraint_rset_002.name °.definition sp_helpconstraint_rset_003.name °.definition sp_helpconstraint_rset_004.name °.definition sp_helptext_rset_001.# Lines of Text sp_helptext_rset_002.number sp_indsuspect_rset_001.Own.Tab.Ind (Obj_ID, Ind_ID) sp_indsuspect_rset_002.Own.Tab.Ind (Obj_ID, Ind_ID)
sp_jdbc_datatype_info_rset_001.TYPE_NAME sp_jdbc_fkeys_rset_001.PK_NAME sp_jdbc_fkeys_rset_002.PK_NAME sp_jdbc_fkeys_rset_003.PK_NAME sp_jdbc_getindexinfo_rset_001.TABLE_NAME °.INDEX_QUALIFIER °.INDEX_NAME °.COLUMN_NAME sp_jdbc_getindexinfo_rset_002.TABLE_NAME °.INDEX_QUALIFIER
°.INDEX_NAME °.COLUMN_NAME sp_jdbc_getsupertypes_rset_001.TYPE_NAME °.SUPERTYPE_NAME sp_jdbc_getversioncolumns_rset_001.COLUMN_NAME sp_jdbc_primarykey_rset_001.PK_NAME sp_jdbc_stored_procedures_rset_001.PROCEDURE_NAME °.SPECIFIC_NAME sp_jdbc_stored_procedures_rset_002.PROCEDURE_NAME °.num_result_sets
sp_jdbc_stored_procedures_rset_003.FUNCTION_NAME sp_jdbc_tables_rset_001.TABLE_NAME sp_modifystats_rset_001.sqlbNoName58 sp_modifystats_rset_002.sqlbNoName59 sp_modifystats_rset_003.sqlbNoName60 sp_odbc_datatype_info_rset_001.TYPE_NAME sp_odbc_fkeys_rset_001.PK_NAME sp_odbc_fkeys_rset_002.PK_NAME sp_odbc_getindexinfo_rset_001.TABLE_NAME °.INDEX_QUALIFIER
°.INDEX_NAME sp_odbc_getindexinfo_rset_002.TABLE_NAME °.INDEX_QUALIFIER °.INDEX_NAME sp_odbc_getprocedurecolumns_rset_001.PROCEDURE_NAME °.COLUMN_NAME sp_odbc_getprocedurecolumns_rset_002.PROCEDURE_NAME °.COLUMN_NAME sp_odbc_getversioncolumns_rset_002.COLUMN_NAME sp_odbc_getversioncolumns_rset_003.COLUMN_NAME
°.TYPE_NAME sp_odbc_primarykey_rset_001.PK_NAME sp_odbc_stored_procedures_rset_001.PROCEDURE_NAME sp_odbc_tables_rset_001.TABLE_NAME sp_oledb_columns_rset_001.TABLE_NAME °.COLUMN_NAME sp_oledb_columns_rset_002.TABLE_NAME °.COLUMN_NAME sp_oledb_datatype_info_rset_001.TYPE_NAME sp_oledb_datatype_info_rset_002.TYPE_NAME
sp_oledb_datatype_info_rset_003.TYPE_NAME sp_oledb_fkeys_rset_001.PK_NAME sp_oledb_getprocedurecolumns_rset_001.PROCEDURE_NAME °.PARAMETER_NAME sp_oledb_getprocedurecolumns_rset_002.PROCEDURE_NAME °.PARAMETER_NAME sp_oledb_primarykey_rset_001.PK_NAME sp_oledb_statistics_rset_001.TABLE_NAME sp_oledb_stored_procedures_rset_001.PROCEDURE_NAME sp_oledb_tables_rset_001.TABLE_NAME
sp_oledb_tables_rset_002.TABLE_NAME sp_oledb_views_rset_001.TABLE_NAME sp_procxmode_rset_001.procedure name sp_procxmode_rset_002.procedure name sp_special_columns_rset_002.column_name sp_special_columns_rset_003.column_name °.type_name sp_sproc_columns_rset_001.procedure_name °.column_name sp_sproc_columns_rset_002.procedure_name
°.column_name sp_sql_type_name_rset_003.name sp_sql_type_name_rset_004.name sp_statistics_rset_001.table_name °.index_qualifier °.index_name sp_statistics_rset_002.table_name °.index_qualifier °.index_name sp_stored_procedures_rset_001.procedure_name
sp_tab_suspectptn_rset_001.Partition type, Own.Tab.Ind (Obj_ID, Ind_ID) sp_tab_suspectptn_rset_002.Partition Type, Own.Tab.Ind.Ptn (Obj_ID, Ind_ID, Ptn_ID) sp_tables_rset_001.table_name

DEPENDENCIES
PROCS AND TABLES USED
read_writes table sybsystemprocs..sysobjects  
read_writes table sybsystemprocs..syspartitions  
read_writes table sybsystemprocs..syscolumns  
read_writes table sybsystemprocs..sysindexes  
calls proc sybsystemprocs..sp_getmessage  
   reads table sybsystemprocs..sysusermessages  
   reads table master..syslanguages (1)  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table master..sysmessages (1)  
read_writes table sybsystemprocs..sysattributes  
read_writes table sybsystemprocs..systypes