DatabaseProcApplicationCreatedLinks
sybsystemprocssp_rebuild_text  31 Aug 14Defects Dependencies

1     
2     
3     /* 
4     ** Messages for "sp_rebuild_text"	18925
5     **
6     ** 17260, "Can't run %1! from within a transaction." 
7     ** 17590, "The specified database does not exist."
8     ** 18301, "Database name '%1!' is not the current database."
9     ** 18925  "sp_rebuild_text failed. Check the SQL Server error log file."
10    */
11    
12    create procedure sp_rebuild_text
13        @dbname varchar(255) /* database name */
14    as
15    
16        /*
17        **  If we're in a transaction, disallow this since it might make recovery
18        **  impossible.
19        */
20        if @@trancount > 0
21        begin
22            /*
23            ** 17260, "Can't run %1! from within a transaction." 
24            */
25            raiserror 17260, "sp_rebuild_text"
26            return (1)
27        end
28    
29        set chained off
30    
31        set transaction isolation level 1
32    
33        /*
34        **  Make sure the database exists.
35        */
36        if not exists (select * from master.dbo.sysdatabases
37                where name = @dbname)
38        begin
39            /* 17590, "The specified database does not exist." */
40            raiserror 17590
41            return (1)
42        end
43    
44        /*
45        **  Make sure that we are in the database specified
46        **  by @dbname.
47        */
48        if @dbname != db_name()
49        begin
50            /*
51            ** 18301, "Database name '%1!' is not the current database."
52            */
53            raiserror 18301, @dbname
54            return (1)
55        end
56    
57        /*
58        **  Check if user has sa role, proc_role will also do auditing
59        **  if required. proc_role will also print error message if required.
60        */
61        if (proc_role("sa_role") = 0)
62            return (1)
63    
64        /* Uses internal sql to rebuild_text */
65    
66        dbcc rebuild_text("all")
67    
68        if (@@error != 0)
69        begin
70            /*
71            ** 18925, "sp_rebuild_text failed. Check the SQL Server error log file."
72            */
73            raiserror 18925
74            return (1)
75        end
76    
77        return (0)
78    
79    


exec sp_procxmode 'sp_rebuild_text', 'AnyMode'
go

Grant Execute on sp_rebuild_text to public
go
DEFECTS
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public sybsystemprocs..sp_rebuild_text  
 MUCO 3 Useless Code Useless Brackets 26
 MUCO 3 Useless Code Useless Brackets 41
 MUCO 3 Useless Code Useless Brackets 54
 MUCO 3 Useless Code Useless Brackets 61
 MUCO 3 Useless Code Useless Brackets 62
 MUCO 3 Useless Code Useless Brackets 68
 MUCO 3 Useless Code Useless Brackets 74
 MUCO 3 Useless Code Useless Brackets 77
 QISO 3 Set isolation level 31
 MSUB 2 Subquery Marker 36
 MTR1 2 Metrics: Comments Ratio Comments: 61% 12
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 2 = 5dec - 5exi + 2 12
 MTR3 2 Metrics: Query Complexity Complexity: 26 12

DEPENDENCIES
PROCS AND TABLES USED
reads table master..sysdatabases (1)