DatabaseProcApplicationCreatedLinks
sybsystemprocssp_is_dbo  31 Aug 14Defects Dependencies

1     
2     
3     /*
4     ** Description
5     ** 	Finds if the user executing the procedure is the
6     **	database owner.
7     **
8     ** Parameters
9     **	@currdbname	- database name
10    **
11    ** Returns
12    ** 	1 	- User is DBO or alias to DBO
13    **	0	- Otherwise
14    **
15    ** Notes
16    **	It must be called as @currdbname.sp_is_dbo @currdbname
17    */
18    create procedure sp_is_dbo(@currdbname varchar(256))
19    as
20        begin
21            declare @dbo int
22    
23            -- Initialize as non-DBO to handle all exit conditions.
24    
25            select @dbo = 0
26    
27            -- Check for caller's error. We should always call this sproc
28            -- using @currdbname.dbo. so that we are looking up the
29            -- correct sysusers. In case of an error in caller's calling
30            -- convention, flag that by returning that user is not DBO in db.
31    
32            if (@currdbname != db_name())
33            begin
34                select @dbo = 0
35            end
36    
37            -- Is this login the dbo of the current db?
38            -- If a dbo has 'setuser' to some other user, we do not recognize
39            -- him/her as DBO any longer. This is a minor restriction that we
40            -- only allow a real DBO to perform any command, and not under setuser.
41    
42            else if exists (select 1 from sysusers
43                    where uid = 1 and suid = suser_id())
44                and (user_id() = 1)
45            begin
46                select @dbo = 1
47            end
48            else
49            begin
50                -- Is this login the 'dbo' alias of the db, but w/o sa_role?
51    
52                if exists (select 1 from sysalternates
53                        where suid = suser_id()
54                            and altsuid = (select suid from sysusers
55                                where uid = 1))
56                begin
57                    select @dbo = 1
58                end
59            end
60    
61            return @dbo
62        end
63    


exec sp_procxmode 'sp_is_dbo', 'AnyMode'
go

Grant Execute on sp_is_dbo to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_is_dbo  
 MGTP 3 Grant to public sybsystemprocs..sysalternates  
 MGTP 3 Grant to public sybsystemprocs..sysusers  
 MUCO 3 Useless Code Useless Brackets in create proc 18
 MUCO 3 Useless Code Useless Begin-End Pair 20
 MUCO 3 Useless Code Useless Brackets 32
 MSUB 2 Subquery Marker 42
 MSUB 2 Subquery Marker 52
 MSUB 2 Subquery Marker 54
 MTR1 2 Metrics: Comments Ratio Comments: 57% 18
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 6dec - 1exi + 2 18
 MTR3 2 Metrics: Query Complexity Complexity: 22 18

DEPENDENCIES
PROCS AND TABLES USED
reads table sybsystemprocs..sysusers  
reads table sybsystemprocs..sysalternates