1
2 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3
4 create procedure sp_odbc_databases
5 as
6
7 declare @startedInTransaction bit
8 if (@@trancount > 0)
9 select @startedInTransaction = 1
10 else
11 select @startedInTransaction = 0
12
13
14
15 if @@trancount = 0
16 begin
17 set chained off
18 end
19
20 set transaction isolation level 1
21
22 if (@startedInTransaction = 1)
23 save transaction odbc_keep_temptable_tx
24
25
26 /* Use temporary table to sum up database size w/o using group by */
27 create table #databases(
28 database_name varchar(32),
29 size int)
30
31 /* Insert row for each database */
32 insert into #databases
33 select
34 name,
35 (select sum(size) from master.dbo.sysusages
36 where dbid = d.dbid)
37 from master.dbo.sysdatabases d
38
39 select
40 database_name,
41 /* Convert from number of pages to K */
42 database_size = size * (@@maxpagesize / 1024),
43 remarks = convert(varchar(254), null) /* Remarks are NULL */
44 from #databases
45
46 drop table #databases
47 if (@startedInTransaction = 1)
48 rollback transaction odbc_keep_temptable_tx
49
50 return (0)
51
exec sp_procxmode 'sp_odbc_databases', 'AnyMode'
go
Grant Execute on sp_odbc_databases to public
go