Database | Proc | Application | Created | Links |
sybsystemprocs | sp_rename ![]() | ![]() | 31 Aug 14 | Defects Dependencies |
1 2 /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */ 3 /* 4.8 1.1 06/14/90 sproc/src/password */ 4 5 /* 6 ** Messages for "sp_rename" 17780 7 ** 8 ** 17260, "Can't run %1! from within a transaction." 9 ** 17460, "Object must be in the current database." 10 ** 17240, "'%1!' is not a valid name." 11 ** 17756, "The execution of the stored procedure '%1!' in database 12 ** '%2!' was aborted because there was an error in writing the 13 ** replication log record." 14 ** 17763, "The execution of the stored procedure '%1!' in database '%2!' was aborted because therewas an error in updating the schemacnt column in sysobjects." 15 ** 17780, "There is already a column named '%1!' in table '%2!'." 16 ** 17781, "Column name has been changed." 17 ** 17782, "You do not own a table or column (or index) of that name in the current database." 18 ** 17783, "There is already an index named '%1!' for table '%2!'." 19 ** 17784, "Index name has been changed." 20 ** 17785, "Table or view names beginning with '#' are not allowed." 21 ** 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." 22 ** 17787, "Newname already exists in systypes." 23 ** 17788, "Newname already exists in sysobjects." 24 ** 17789, "Object name has been changed." 25 ** 17968, "The built-in function logschema() failed for '%1!'." 26 ** 18058, "Name of user-defined type name changed." 27 ** 18071, "Set curwrite to the level of table/column." 28 ** 18077, "Set curwrite to the level of index." 29 ** 18078, "Set curwrite to the level of the object in systypes." 30 ** 18079, "Set curwrite to the level of the object in sysobjects." 31 ** 18080, "Certified state of object '%1!' has been set to 'Suspect'" 32 ** 18409, "The built-in function '%1!' failed. Please see 33 ** the other messages printed along with this message." 34 ** 18410, "The replication status of '%1!' is corrupt. Please contact 35 ** Sybase Technical Support." 36 ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters." 37 ** 19412 "Cannot rename a service that is deployed." 38 ** 19819 "Warning: Changing an object or column name may break existing stored procedures, cached statements or other compiled objects." 39 ** 40 */ 41 42 /* 43 ** IMPORTANT NOTE: 44 ** This stored procedure uses the built-in function object_id() in the 45 ** where clause of a select query. If you intend to change this query 46 ** or use the object_id() or db_id() builtin in this procedure, please read the 47 ** READ.ME file in the $DBMS/generic/sproc directory to ensure that the rules 48 ** pertaining to object-id's and db-id's outlined there, are followed. 49 ** 50 ** NOTE: 51 ** All updates to sysindexes are done by forcing the index access via 52 ** 'csysindexes' so that it's clear that only one row is being updated. 53 ** (Multi-row updates to sysindexes are prohibited.) 54 */ 55 56 create procedure sp_rename 57 @objname varchar(512), /* old (current) object name */ 58 @newname varchar(256), /* new name we want to call it */ 59 @indorcol varchar(10) = null /* Index or column to rename */ 60 as 61 62 declare @objid int /* object id of the thing to rename */ 63 declare @index_objid int /* object id from sysindexes */ 64 declare @msg varchar(1024) 65 declare @temp_dbid int 66 declare @temp_objid int 67 declare @curdb_name varchar(255) /* name of current db */ 68 declare @rep_constant smallint /* bit indicating a repl. object */ 69 declare @cur_sysstat smallint /* current sysstat value of object */ 70 declare @rep_obj int /* is the object replicated? */ 71 declare @rep_db_stat int /* rep status of database */ 72 declare @rep_db int /* is the db replicated */ 73 declare @table_or_proc int /* object is a table or procedure */ 74 declare @obj_type char(2) /* type of the object */ 75 declare @user_tran int /* inside a user tran? */ 76 declare @after_image int /* log the after image of the schema */ 77 declare @mod_versionts int /* modify version timestamp after 78 ** logging the schema 79 */ 80 declare @dbname varchar(255) 81 declare @maxobjlen int /* get the length of sysobject.name from syscolumns */ 82 declare @maxuserlen int /* get the length of sysusers.name from syscolumns */ 83 declare @maxtotlen int /* get the Total length of sysobjects.name + sysusers.name*/ 84 declare @lt_rep_get_failed 85 int 86 declare @lt_rep_all int 87 declare @lt_rep_l1 int 88 89 /* 90 ** Running sp_rename inside a transaction would endanger the 91 ** recoverability of the transaction/database. Disallow it. 92 ** Do the @@trancount check before initializing any local variables, 93 ** because "select" statement itself will start a transaction 94 ** if chained mode is on. 95 */ 96 if @@trancount > 0 97 begin 98 /* 99 ** 17260, "Can't run %1! from within a transaction." 100 */ 101 raiserror 17260, "sp_rename" 102 return (1) 103 end 104 else 105 begin 106 set chained off 107 end 108 109 /* 110 ** Initialise objid and index_objid 111 */ 112 select @objid = NULL 113 select @index_objid = NULL 114 /* 115 ** check the length of sysobject.name and sysuser.name 116 */ 117 select @maxobjlen = length from syscolumns 118 where id = object_id("sysobjects") and 119 name = 'name' 120 select @maxuserlen = length from syscolumns 121 where id = object_id("sysusers") and 122 name = 'name' 123 select @maxtotlen = (@maxobjlen + @maxuserlen) + 1 124 125 126 /* check the lengths of the input params */ 127 if char_length(@objname) > @maxtotlen 128 begin 129 /* 130 ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters." 131 */ 132 raiserror 17325, @objname, @maxtotlen 133 return (1) 134 end 135 if char_length(@newname) > @maxobjlen 136 begin 137 /* 138 ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters." 139 */ 140 raiserror 17325, @newname, @maxobjlen 141 return (1) 142 end 143 if ((@indorcol is not null) and (@indorcol not in ('index', 'column'))) 144 begin 145 /* 146 ** 18938, "Invalid third argument '%1!' entered. Valid values are 147 ** {'index'|'column'}" 148 */ 149 raiserror 18938, @indorcol 150 return (1) 151 end 152 153 /* 154 ** Replication constants. 155 */ 156 select @lt_rep_get_failed = - 2, @lt_rep_all = 2048, @lt_rep_l1 = 4096 157 158 set transaction isolation level 1 159 160 if @objname like "%.%.%" 161 begin 162 /* 163 ** 17460, "Object must be in the current database." 164 */ 165 raiserror 17460 166 return (1) 167 end 168 169 /* 170 ** Check to see that the @newname is valid. 171 */ 172 if valid_name(@newname, @maxobjlen) = 0 173 begin 174 /* 175 ** 17240, "'%1!' is not a valid name." 176 */ 177 raiserror 17240, @newname 178 return (1) 179 end 180 181 /* 182 ** Check to see if we are renaming a table/column (or table/index) 183 ** or a table or usertype. 184 ** If @objname is of the form table.column then it's a column. 185 ** In the column case, we need to extract and verify the table and 186 ** column names and make sure the user owns the table that is getting 187 ** the rule bound. 188 */ 189 if @objname like "%.%" 190 begin 191 declare @tabname varchar(255) /* name of table */ 192 declare @colname varchar(255) /* name of column */ 193 declare @colid smallint /* colid of the column */ 194 195 /* 196 ** Get the table name out. 197 */ 198 select @tabname = substring(@objname, 1, charindex(".", @objname) - 1) 199 select @colname = substring(@objname, charindex(".", @objname) + 1, @maxtotlen) 200 201 /* 202 ** If no third parameter was specified, or, if third parameter 203 ** was specified as 'index', see if there is an index 204 ** of this name in a table owned by the user, and keep it in a 205 ** local variable. 206 */ 207 if (@indorcol is null or @indorcol = 'index') 208 begin 209 select @index_objid = sysindexes.id, @colid = sysindexes.indid 210 from sysobjects, sysindexes 211 where sysindexes.id = sysobjects.id 212 and sysobjects.name = @tabname 213 and sysindexes.name = @colname 214 and sysindexes.indid != 0 215 and sysobjects.sysstat & 7 = 3 /* user table */ 216 and sysobjects.uid = user_id() 217 218 end 219 220 /* 221 ** Now check to see that the column exists in a table owned 222 ** by the user. Don't do this if the user explicitly specified 223 ** that this is an index. 224 */ 225 226 if (@indorcol is null or @indorcol != 'index') 227 begin 228 select @objid = syscolumns.id, @colid = syscolumns.colid 229 from sysobjects, syscolumns 230 where syscolumns.id = sysobjects.id 231 and sysobjects.name = @tabname 232 and syscolumns.name = @colname 233 and (sysobjects.sysstat & 7 = 2 /* user table */ 234 or sysobjects.sysstat & 7 = 3) /* view */ 235 and sysobjects.uid = user_id() 236 end 237 238 /* 239 ** Did we find it? If not, it might be an index name so we'll 240 ** check in the next case. If the user explicitly specified 241 ** that this is an index name, check in the next case as well. 242 */ 243 if @objid is not null 244 begin 245 /* 246 ** If there is an index as well as a column of the same 247 ** name, raise an error to warn the user of this ambiguity. 248 */ 249 if @index_objid is not null 250 begin 251 /* 252 ** 18939, "There is an index as well as a column of 253 ** the name '%1!'. Please specify as the third 254 ** argument whether you would like to rename 'index' 255 ** or 'column'" 256 */ 257 raiserror 18939, @colname 258 return (1) 259 end 260 261 /* 262 ** Cannot modify the name of a function-based index key. 263 ** The name is a system name created internally. 264 */ 265 if exists (select 1 266 from syscolumns 267 where id = @objid and 268 colid = @colid and 269 status3 & 1 = 1) 270 begin 271 /* 272 ** 17786, "Object name cannot be changed either 273 ** because it does not exist in this database, 274 ** or you don't own it, or it is a system name." 275 */ 276 raiserror 17786 277 return (1) 278 end 279 280 /* 281 ** Check to make sure that there is no already a column 282 ** that has the new name. 283 */ 284 if exists (select * 285 from syscolumns 286 where id = @objid 287 and name = @newname) 288 begin 289 /* 290 ** 17780, "There is already a column named '%1!' in table '%2!'." 291 */ 292 raiserror 17780, @newname, @tabname 293 return (1) 294 end 295 296 /* determine the object's replication status */ 297 298 /* Replication enabled flag is 8000H (which is -32768D) */ 299 select @rep_constant = - 32768 300 301 select 302 @cur_sysstat = sysstat 303 from 304 sysobjects holdlock 305 where 306 id = @objid 307 308 if (@cur_sysstat & @rep_constant) = @rep_constant 309 begin 310 select @rep_obj = 1 311 end 312 else 313 begin 314 select @rep_obj = 0 315 end 316 317 /* determine the database's replication status */ 318 select @rep_db_stat = getdbrepstat() 319 if (@rep_db_stat = @lt_rep_get_failed) 320 begin 321 /* 322 ** 18409, "The built-in function getdbrepstat() 323 ** failed. Please see the other messages printed 324 ** along with this message." 325 */ 326 raiserror 18409, "getdbrepstat" 327 return (1) 328 end 329 else 330 begin 331 if ((@rep_db_stat & @lt_rep_all = @lt_rep_all) or 332 (@rep_db_stat & @lt_rep_l1 = @lt_rep_l1)) 333 select @rep_db = 1 334 else 335 select @rep_db = 0 336 end 337 338 /* 339 ** IMPORTANT: The name rs_logexec is significant 340 ** and is used by Replication Server. 341 */ 342 begin transaction rs_logexec 343 344 /* if the object is replicated, log the schema before 345 ** changing the column name 346 */ 347 if ((@rep_obj = 1) or (@rep_db = 1)) 348 begin 349 select @user_tran = 0 350 select @after_image = 0 351 select @mod_versionts = 1 352 if (logschema(@objid, @user_tran, @after_image, 353 @mod_versionts) != 1) 354 begin 355 /* 356 ** 17968 "The built-in function logschema() 357 ** failed for '%1!'." 358 */ 359 raiserror 17968, @tabname 360 361 rollback transaction rs_logexec 362 return (1) 363 end 364 end 365 366 /* 367 ** Update schema count for this table or view. 368 */ 369 if (schema_inc(object_id(@tabname), 2) != 1) 370 begin 371 /* 372 ** 17763, "The execution of the stored procedure '%1!' 373 ** in database '%2!' was aborted because there 374 ** was an error in updating the column 375 ** schemacnt in sysobjects." 376 */ 377 select @dbname = db_name() 378 raiserror 17763, "sp_rename", @dbname 379 rollback transaction rs_logexec 380 return (1) 381 end 382 383 /* 384 ** Go ahead and change the column name. 385 */ 386 update syscolumns 387 set name = @newname 388 from syscolumns 389 where id = @objid 390 and colid = @colid 391 /* 392 ** If we are renaming the SYB_IDENTITY_COL 393 ** then turn off the COL_AUTO_IDENTITY bit (0x2). 394 ** Note that we can never rename a column to 395 ** SYB_IDENTIY_COL (since valid_name() will fail) 396 ** so don't worry about the converse. 397 */ 398 if (@colname = "SYB_IDENTITY_COL") 399 begin 400 update syscolumns 401 set status = (~ 2 & status) 402 from syscolumns 403 where id = @objid 404 and colid = @colid 405 end 406 407 /* 408 ** Write the log record to replicate this invocation 409 ** of the stored procedure. 410 */ 411 if (logexec() != 1) 412 begin 413 /* 414 ** 17756, "The execution of the stored procedure '%1!' 415 ** in database '%2!' was aborted because there 416 ** was an error in writing the replication log 417 ** record." 418 */ 419 select @dbname = db_name() 420 raiserror 17756, "sp_rename", @dbname 421 422 rollback transaction rs_logexec 423 return (1) 424 end 425 426 /* commit the transaction */ 427 commit transaction 428 429 /* 430 ** 17781, "Column name has been changed." 431 */ 432 exec sp_getmessage 17781, @msg output 433 print @msg 434 /* 435 ** 19819 "Warning: Changing an object or column name may 436 ** break existing stored procedures, cached statements or 437 ** other compiled objects." 438 */ 439 exec sp_getmessage 19819, @msg output 440 print @msg 441 return (0) 442 end 443 444 /* 445 ** Might be an index name. 446 */ 447 else 448 begin 449 /* 450 ** We have already obtained the objid from sysindexes. 451 */ 452 select @objid = @index_objid 453 454 /* 455 ** If @objid is still NULL then that means it isn't an 456 ** index name. We checked above to see if it was a column 457 ** name so now it's time to give up. 458 */ 459 if @objid is null 460 begin 461 /* 462 ** 17782, "You do not own a table or column (or index) of that name in the current database." 463 */ 464 raiserror 17782 465 return (1) 466 end 467 468 /* 469 ** Check to make sure that there is no already an index 470 ** that has the new name. 471 */ 472 if exists (select * 473 from sysindexes 474 where id = @objid 475 and name = @newname 476 and indid > 0) 477 begin 478 /* 479 ** 17783, "There is already an index named '%1!' for table '%2!'." 480 */ 481 raiserror 17783, @newname, @tabname 482 return (1) 483 end 484 485 /* 486 ** IMPORTANT: The name rs_logexec is significant 487 ** and is used by Replication Server. 488 */ 489 begin transaction rs_logexec 490 491 /* 492 ** Go ahead and change the index name. 493 */ 494 update sysindexes 495 set name = @newname 496 from sysindexes 497 where id = @objid and indid = @colid 498 plan "(update (i_scan csysindexes sysindexes))" 499 500 /* 501 ** We updated a sysindexes row. We also need to update the 502 ** in-core structure representing this sysindexes row as the 503 ** sysindexes rows cache is not a write thru cache. 504 */ 505 select @temp_dbid = db_id() 506 507 dbcc refreshides(@temp_dbid, @objid, @colid, "indname") 508 509 /* 510 ** If there was a error in rollback the update to sysindexes. 511 ** dbcc refreshides would have printed the error message. 512 */ 513 if @@error != 0 514 begin 515 rollback transaction rs_logexec 516 return (1) 517 end 518 519 /* 520 ** Write the log record to replicate this invocation 521 ** of the stored procedure. 522 */ 523 if (logexec() != 1) 524 begin 525 /* 526 ** 17756, "The execution of the stored procedure '%1!' 527 ** in database '%2!' was aborted because there 528 ** was an error in writing the replication log 529 ** record." 530 */ 531 select @dbname = db_name() 532 raiserror 17756, "sp_rename", @dbname 533 534 rollback transaction rs_logexec 535 return (1) 536 end 537 538 commit transaction 539 /* 540 ** 17784, "Index name has been changed." 541 */ 542 exec sp_getmessage 17784, @msg output 543 print @msg 544 return (0) 545 end 546 end 547 548 /* 549 ** Check to see if the object exists and is owned by the user. 550 ** It will either be in the sysobjects table or the systypes table. 551 ** Check sysobjects first. 552 ** System objects have ids < 100 and we don't allow their names to change. 553 */ 554 if exists (select id 555 from sysobjects 556 where id = object_id(@objname) 557 and uid = user_id() 558 and id > 99) 559 /* 560 ** Don't allow the newname to begin with #. 561 */ 562 begin 563 if substring(@newname, 1, 1) = "#" 564 begin 565 /* 566 ** 17785, "Table or view names beginning with '#' are not allowed." 567 */ 568 raiserror 17785 569 return (1) 570 end 571 end 572 573 /* 574 ** It's not in sysobjects so check systypes. 575 */ 576 else 577 begin 578 select @objid = usertype 579 from systypes 580 where name = @objname 581 and uid = user_id() 582 and usertype > 99 583 584 /* 585 ** It's nowhere to be found so quit. 586 */ 587 if @objid is NULL 588 begin 589 /* 590 ** 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." 591 */ 592 raiserror 17786 593 return (1) 594 end 595 596 /* Check that newname doesn't already exist. */ 597 if exists (select * 598 from systypes 599 where name = @newname) 600 begin 601 /* 602 ** 17787, "Newname already exists in systypes." 603 */ 604 raiserror 17787 605 return (1) 606 end 607 608 /* 609 ** IMPORTANT: This transaction name is significant and is used by 610 ** Replication Server 611 */ 612 begin transaction rs_logexec 613 614 /* 615 ** Change the name of a datatype 616 */ 617 update systypes 618 set name = @newname 619 where usertype = @objid 620 621 /* 622 ** Write the log record to replicate this invocation 623 ** of the stored procedure. 624 */ 625 if (logexec() != 1) 626 begin 627 /* 628 ** 17756, "The execution of the stored procedure '%1!' 629 ** in database '%2!' was aborted because there 630 ** was an error in writing the replication log 631 ** record." 632 */ 633 select @dbname = db_name() 634 raiserror 17756, "sp_setreptable", @dbname 635 636 rollback transaction rs_logexec 637 return (1) 638 end 639 commit transaction 640 641 /* 642 ** 18058, "Name of user-defined type name changed." 643 */ 644 exec sp_getmessage 18058, @msg output 645 print @msg 646 return (0) 647 end 648 649 /* 650 ** It might be a table so update the index entry for the table IF it has 651 ** no clustered index. No clustered index means that there is an entry 652 ** for the table under the @objid with indid = 0. 653 */ 654 655 /* Check that newname doesn't already exist. */ 656 if exists (select * 657 from sysobjects 658 where name = @newname 659 and uid = user_id()) 660 begin 661 /* 662 ** 17788, "Newname already exists in sysobjects." 663 */ 664 raiserror 17788 665 return (1) 666 end 667 668 /* 669 ** IMPORTANT: This transaction name is significant and is used by 670 ** Replication Server 671 */ 672 begin transaction rs_logexec 673 674 /* if the object is a table or a procedure, we may have to log its 675 ** schema before/after changing its name 676 */ 677 if exists ( 678 select id 679 from sysobjects where 680 (type = "U" or type = "P" or type = "WS") and 681 name = @objname 682 ) 683 begin 684 select @table_or_proc = 1 685 end 686 else 687 begin 688 select @table_or_proc = 0 689 end 690 691 /* 692 ** Is the object a service? 693 */ 694 695 if exists ( 696 select id 697 from sysobjects where 698 type = "WS" and 699 name = @objname 700 ) 701 begin 702 /* 703 ** Lock the specific row in the sysattributes table to 704 ** avoid race conditions with sp_webservices deploy and 705 ** undeploy. 706 */ 707 708 select @temp_objid = object from sysattributes holdlock where 709 class = 18 and 710 attribute = 6 and 711 object = object_id(@objname) 712 713 /* 714 ** If the service is deployed do not allow the rename 715 ** to go through. 716 */ 717 718 if exists ( 719 select object_info3 from sysattributes where 720 object = object_id(@objname) and 721 class = 18 and 722 attribute = 6 and 723 object_info3 & 128 = 128 724 ) 725 begin 726 /* 727 ** 19412, "Cannot rename a service that is deployed. " 728 */ 729 730 raiserror 19412 731 rollback transaction rs_logexec 732 return (1) 733 end 734 end 735 736 /* determine the object's replication status if it is a table or 737 ** a procedure and log its schema if necessary 738 */ 739 if (@table_or_proc = 1) 740 begin 741 742 /* Replication enabled flag is 8000H (which is -32768D) */ 743 select @rep_constant = - 32768 744 745 select 746 @cur_sysstat = sysstat 747 from 748 sysobjects holdlock 749 where 750 id = object_id(@objname) 751 752 if (@cur_sysstat & @rep_constant) = @rep_constant 753 begin 754 select @rep_obj = 1 755 end 756 else 757 begin 758 select @rep_obj = 0 759 end 760 761 /* check if db is replicated */ 762 select @rep_db_stat = getdbrepstat() 763 if (@rep_db_stat = @lt_rep_get_failed) 764 begin 765 /* 766 ** 18409, "The built-in function getdbrepstat() 767 ** failed. Please see the other messages printed 768 ** along with this message." 769 */ 770 raiserror 18409 771 rollback transaction rs_logexec 772 return (1) 773 end 774 else 775 begin 776 if ((@rep_db_stat & @lt_rep_all = @lt_rep_all) or 777 (@rep_db_stat & @lt_rep_l1 = @lt_rep_l1)) 778 select @rep_db = 1 779 else 780 select @rep_db = 0 781 end 782 783 /* 784 ** if db is replicated, and object is user table, then the 785 ** user table is replicated even if it is not explicitly 786 ** marked for replication 787 */ 788 if ((@rep_obj = 0) and (@rep_db = 1)) 789 begin 790 if exists ( 791 select id from 792 sysobjects where 793 (type = "U") and 794 (id = object_id(@objname)) 795 ) 796 begin 797 select @rep_obj = 1 798 end 799 end 800 801 if (@rep_obj = 1) 802 begin 803 select @user_tran = 0 804 select @after_image = 0 805 select @mod_versionts = 1 806 if (logschema(object_id(@objname), @user_tran, 807 @after_image, @mod_versionts) != 1) 808 begin 809 /* 810 ** 17968 "The built-in function logschema() 811 ** failed for '%1!'." 812 */ 813 raiserror 17968, @objname 814 815 rollback transaction rs_logexec 816 return (1) 817 end 818 end 819 end 820 821 /* 822 ** Update schema count for this table or view. 823 */ 824 select @obj_type = type 825 from sysobjects where id = object_id(@objname) 826 827 if (@obj_type = 'U' or @obj_type = 'V') 828 begin 829 if (schema_inc(object_id(@objname), 2) != 1) 830 begin 831 /* 832 ** 17763, "The execution of the stored procedure '%1!' 833 ** in database '%2!' was aborted because there 834 ** was an error in updating the column 835 ** schemacnt in sysobjects." 836 */ 837 select @dbname = db_name() 838 raiserror 17763, "sp_rename", @dbname 839 rollback transaction rs_logexec 840 return (1) 841 end 842 end 843 844 update sysobjects 845 set name = @newname 846 where id = object_id(@objname) 847 848 /* 849 ** If the object is a proxy table, update sysattributes 850 */ 851 update sysattributes 852 set object_cinfo = @newname 853 where object_cinfo = @objname and class = 9 854 855 /* 856 ** This might not do anything -- only if we are dealing with a 857 ** table that has no clustered index. 858 ** Also change the name of the text entry, if any. 859 */ 860 update sysindexes 861 set name = @newname 862 where id = object_id(@objname) and indid = 0 863 plan "(update (i_scan csysindexes sysindexes))" 864 865 /* 866 ** We updated a sysindexes row. We also need to update the 867 ** in-core structure representing this sysindexes row as the 868 ** sysindexes rows cache is not a write thru cache. 869 */ 870 select @temp_dbid = db_id() 871 select @temp_objid = object_id(@objname) 872 873 dbcc refreshides(@temp_dbid, @temp_objid, 0, "indname") 874 875 /* dbcc refreshides would print a message in case of error */ 876 if @@error != 0 877 begin 878 rollback transaction rs_logexec 879 return (1) 880 end 881 882 update sysindexes 883 set name = "t" + @newname 884 where id = object_id(@objname) and indid = 255 885 plan "(update (i_scan csysindexes sysindexes))" 886 887 /* 888 ** We updated a sysindexes row. We also need to update the 889 ** in-core structure representing this sysindexes row as the 890 ** sysindexes rows cache is not a write thru cache. 891 */ 892 dbcc refreshides(@temp_dbid, @temp_objid, 255, "indname") 893 894 /* dbcc refreshides would print a message in case of error */ 895 if @@error != 0 896 begin 897 rollback transaction rs_logexec 898 return (1) 899 end 900 901 /* 902 ** We also must update the object name in the descriptor 903 ** otherwise, in the cache, the object would be under the 904 ** old name. 905 */ 906 dbcc chgobjname(@objname, @newname) 907 908 if @@error != 0 909 begin 910 rollback transaction rs_logexec 911 return (1) 912 end 913 914 /* 915 ** Write the log record to replicate this invocation 916 ** of the stored procedure. 917 */ 918 if (logexec() != 1) 919 begin 920 /* 921 ** 17756, "The execution of the stored procedure '%1!' 922 ** in database '%2!' was aborted because there 923 ** was an error in writing the replication log 924 ** record." 925 */ 926 select @dbname = db_name() 927 raiserror 17756, "sp_rename", @dbname 928 929 rollback transaction rs_logexec 930 return (1) 931 end 932 933 commit transaction 934 935 /* 936 ** 17789, "Object name has been changed." 937 */ 938 exec sp_getmessage 17789, @msg output 939 print @msg 940 941 /* 942 ** 19819 "Warning: Changing an object or column name may break existing stored procedures, cached statements or other compiled objects." 943 */ 944 exec sp_getmessage 19819, @msg output 945 print @msg 946 947 return (0) 948
exec sp_procxmode 'sp_rename', 'AnyMode' go Grant Execute on sp_rename to public go
DEFECTS | |
![]() | 342 |
![]() | 427 |
![]() | 489 |
![]() | 538 |
![]() | 612 |
![]() | 639 |
![]() | sybsystemprocs..sysattributes |
![]() | 387 |
![]() | 495 |
![]() | 618 |
![]() | 845 |
![]() | 852 |
![]() | 861 |
![]() (id, indid) Intersection: {indid} | 213 |
![]() | 214 |
![]() | 476 |
![]() | 582 |
![]() | 619 |
![]() | 619 |
![]() | 709 |
![]() | 710 |
![]() | 721 |
![]() | 722 |
![]() | 853 |
![]() | 862 |
![]() | 884 |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | 386 |
![]() | 400 |
![]() | 432 |
![]() | 439 |
![]() | 494 |
![]() | 542 |
![]() | 617 |
![]() | 644 |
![]() | 844 |
![]() | 851 |
![]() | 860 |
![]() | 882 |
![]() | 938 |
![]() | 944 |
![]() | 102 |
![]() | 133 |
![]() | 141 |
![]() | 143 |
![]() | 150 |
![]() | 166 |
![]() | 178 |
![]() | 207 |
![]() | 226 |
![]() | 258 |
![]() | 277 |
![]() | 293 |
![]() | 319 |
![]() | 327 |
![]() | 331 |
![]() | 347 |
![]() | 352 |
![]() | 362 |
![]() | 369 |
![]() | 380 |
![]() | 398 |
![]() | 411 |
![]() | 423 |
![]() | 441 |
![]() | 465 |
![]() | 482 |
![]() | 516 |
![]() | 523 |
![]() | 535 |
![]() | 544 |
![]() | 569 |
![]() | 593 |
![]() | 605 |
![]() | 625 |
![]() | 637 |
![]() | 646 |
![]() | 665 |
![]() | 732 |
![]() | 739 |
![]() | 763 |
![]() | 772 |
![]() | 776 |
![]() | 788 |
![]() | 801 |
![]() | 806 |
![]() | 816 |
![]() | 827 |
![]() | 829 |
![]() | 840 |
![]() | 879 |
![]() | 898 |
![]() | 911 |
![]() | 918 |
![]() | 930 |
![]() | 947 |
![]() | 618 |
![]() | 845 |
![]() | 852 |
![]() | 386 |
![]() | 400 |
![]() | 494 |
![]() | 117 |
![]() | 120 |
![]() | 708 |
![]() | 494 |
![]() | 860 |
![]() | 882 |
![]() | 158 |
![]() | 210 |
![]() | 229 |
![]() | 210 |
![]() | 210 |
![]() | 229 |
![]() | 229 |
![]() (id, number, colid) Intersection: {id} | 118 |
![]() (id, number, colid) Intersection: {id} | 121 |
![]() (id, number, colid) Intersection: {colid, id} | 267 |
![]() (id, number, colid) Intersection: {id} | 286 |
![]() (id, number, colid) Intersection: {colid, id} | 389 |
![]() (id, number, colid) Intersection: {colid, id} | 403 |
![]() (name, uid) Intersection: {name} | 680 |
![]() (name, uid) Intersection: {name} | 698 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object, class, attribute} | 709 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object, object_info3, attribute, class} | 720 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {class, object_cinfo} | 853 |
![]() | 67 |
![]() | 265 |
![]() | 284 |
![]() | 472 |
![]() | 554 |
![]() | 597 |
![]() | 656 |
![]() | 677 |
![]() | 695 |
![]() | 718 |
![]() | 790 |
![]() | 56 |
![]() | 56 |
![]() | 56 |
![]() | 209 |
![]() | 228 |
DEPENDENCIES |
PROCS AND TABLES USED calls proc sybsystemprocs..sp_getmessage ![]() reads table sybsystemprocs..sysusermessages ![]() reads table master..sysmessages (1) ![]() reads table master..syslanguages (1) ![]() calls proc sybsystemprocs..sp_validlang ![]() reads table master..syslanguages (1) ![]() read_writes table sybsystemprocs..sysindexes ![]() read_writes table sybsystemprocs..syscolumns ![]() read_writes table sybsystemprocs..systypes ![]() read_writes table sybsystemprocs..sysobjects ![]() read_writes table sybsystemprocs..sysattributes ![]() |