Database | Proc | Application | Created | Links |
sybsystemprocs | sp_dropdevice ![]() | ![]() | 31 Aug 14 | Defects Dependencies |
1 2 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */ 3 /* 4.8 1.1 06/14/90 sproc/src/dropdevice */ 4 5 /* 6 ** Messages for "sp_dropdevice" 17482 7 ** 8 ** 17260, "Can't run %1! from within a transaction." 9 ** 17471, "No such device exists -- run sp_helpdevice to list the DataServer devices." 10 ** 17482, "Device is being used by a database. You can't drop it." 11 ** 17483, "Device dropped." 12 */ 13 14 create procedure sp_dropdevice 15 @logicalname varchar(255) /* logical name of the device */ 16 17 as 18 declare @msg varchar(1024) 19 declare @len1 int, @len2 int 20 declare @status int 21 declare @status2 int 22 declare @factor int 23 declare @adbclass int 24 25 select @adbclass = 28 26 27 /* 28 ** If we're in a transaction, disallow this since it might make recovery 29 ** impossible. 30 */ 31 if @@trancount > 0 32 begin 33 /* 34 ** 17260, "Can't run %1! from within a transaction." 35 */ 36 raiserror 17260, "sp_dropdevice" 37 return (1) 38 end 39 else 40 begin 41 set chained off 42 end 43 44 set transaction isolation level 1 45 46 /* check if user has sa role, proc_role will also do auditing 47 ** if required. proc_role will also print error message if required. 48 */ 49 50 if (proc_role("sa_role") = 0) 51 return (1) 52 53 /* 54 ** Check and make sure that the device actually exists. 55 */ 56 if not exists (select * 57 from master.dbo.sysdevices 58 where name = @logicalname) 59 begin 60 /* 61 ** 17471, "No such device exists -- run sp_helpdevice to list the DataServer devices." 62 */ 63 raiserror 17471 64 return (1) 65 end 66 67 /* 68 ** Check and make sure that no database is using the device. 69 ** If so, print out who is using it and exit. 70 */ 71 if exists (select * 72 from master.dbo.sysdatabases a, master.dbo.sysusages b, 73 master.dbo.sysdevices c 74 where a.dbid = b.dbid 75 and b.vdevno = c.vdevno 76 and ((c.status & 6 != 0) or (c.status2 & 8 != 0)) 77 and c.name = @logicalname) 78 begin 79 /* 80 ** 17482, "Device is being used by a database. You can't drop it." 81 */ 82 raiserror 17482 83 84 select @factor = @@maxpagesize / @@pagesize 85 86 select @len1 = max(datalength(a.name)), 87 @len2 = max(datalength(c.name)) 88 from master.dbo.sysdatabases a, master.dbo.sysusages b, 89 master.dbo.sysdevices c 90 where a.dbid = b.dbid 91 and b.vdevno = c.vdevno 92 and ((c.status & 6 != 0) or (c.status2 & 8 != 0)) 93 and c.name = @logicalname 94 95 if (@len1 > 23 or @len2 > 21) 96 select database_name = a.name, 97 device = c.name, 98 size = convert(varchar(25), (size / 512) * @factor) + " MB" 99 from master.dbo.sysdatabases a, master.dbo.sysusages b, 100 master.dbo.sysdevices c 101 where a.dbid = b.dbid 102 and b.vdevno = c.vdevno 103 and ((c.status & 6 != 0) or (c.status2 & 8 != 0)) 104 and c.name = @logicalname 105 order by a.name, c.name, size 106 else 107 select database_name = convert(char(23), a.name), 108 device = convert(char(21), c.name), 109 size = convert(varchar(25), (size / 512) * @factor) + " MB" 110 from master.dbo.sysdatabases a, master.dbo.sysusages b, 111 master.dbo.sysdevices c 112 where a.dbid = b.dbid 113 and b.vdevno = c.vdevno 114 and ((c.status & 6 != 0) or (c.status2 & 8 != 0)) 115 and c.name = @logicalname 116 order by a.name, c.name, size 117 118 return (1) 119 end 120 else if exists (select 1 121 from master..sysattributes a 122 where a.class = @adbclass 123 and a.object_type = 'D' 124 and a.attribute = 1 125 and a.object_cinfo = @logicalname) 126 begin 127 /* 128 ** 17482, "Device is being used by a database. You can't drop it." 129 */ 130 raiserror 17482 131 132 select convert(char(30), name), convert(char(40), char_value) 133 from master.dbo.sysdatabases a, master.dbo.sysattributes b 134 where b.class = @adbclass 135 and b.object_type = 'D' 136 and b.attribute = 1 137 and b.object_cinfo = @logicalname 138 and b.object = a.dbid 139 140 return (1) 141 end 142 143 /* 144 ** Everything's ok so drop the device. 145 */ 146 select @status = status from master.dbo.sysdevices 147 where name = @logicalname 148 149 select @status2 = status2 from master.dbo.sysdevices 150 where name = @logicalname 151 /* 152 ** If database device or cache device (status2 & 8), close it and remove it 153 ** from the sysdevices table using "disk release" command. If dump device, 154 ** remove it from sysdevices table. 155 **/ 156 if (((@status & 6) != 0) or ((@status2 & 8) != 0)) 157 disk release name = @logicalname 158 else 159 delete master.dbo.sysdevices 160 where name = @logicalname 161 if (@@error != 0) 162 return (1) 163 164 /* 165 ** 17483, "Device dropped." 166 */ 167 exec sp_getmessage 17483, @msg output 168 print @msg 169 170 return (0) 171
exec sp_procxmode 'sp_dropdevice', 'AnyMode' go Grant Execute on sp_dropdevice to public go
RESULT SETS | |
sp_dropdevice_rset_003 | |
sp_dropdevice_rset_002 | |
sp_dropdevice_rset_001 |
DEFECTS | |
![]() | master..sysattributes |
![]() | 122 |
![]() | 122 |
![]() | 124 |
![]() | 134 |
![]() | 134 |
![]() | 136 |
![]() | 138 |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | 132 |
![]() | 159 |
![]() | 167 |
![]() | 37 |
![]() | 50 |
![]() | 51 |
![]() | 64 |
![]() | 95 |
![]() | 118 |
![]() | 140 |
![]() | 156 |
![]() | 161 |
![]() | 162 |
![]() | 170 |
![]() | 96 |
![]() | 107 |
![]() | 132 |
![]() | 44 |
![]() | 72 |
![]() | 88 |
![]() | 99 |
![]() | 110 |
![]() | 133 |
![]() | 132 |
![]() | 132 |
![]() | 98 |
![]() | 109 |
![]() | 132 |
![]() | 132 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_type, object_cinfo, attribute, class} | 122 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_type, object_cinfo, attribute, class} | 134 |
![]() | 96 |
![]() | 107 |
![]() | 132 |
![]() | 56 |
![]() | 71 |
![]() | 120 |
![]() | 14 |
![]() | 14 |
![]() | 14 |
![]() | 71 |
![]() | 86 |
![]() | 96 |
![]() | 107 |
![]() | 132 |
DEPENDENCIES |
PROCS AND TABLES USED calls proc sybsystemprocs..sp_getmessage ![]() reads table master..sysmessages (1) ![]() reads table master..syslanguages (1) ![]() reads table sybsystemprocs..sysusermessages ![]() calls proc sybsystemprocs..sp_validlang ![]() reads table master..syslanguages (1) ![]() reads table master..sysusages (1) ![]() read_writes table master..sysdevices (1) ![]() reads table master..sysdatabases (1) ![]() reads table master..sysattributes (1) ![]() |