INF: Determining User Segments from Segmap ValuesID: Q101241
|
This article describes a stored procedure which can be used to determine which user segments map to a Microsoft SQL Server device based on the values from the master.dbo.sysusages segmap column.
One difficulty in administering databases in which user segments have
been defined is determining which segments map to each database device.
Each user segment in a database is assigned a segment number unique in
that database, this number is recorded in the dbo.syssegments table in
each database. The master.dbo.sysusages table indicates how each
database maps to its devices. The segmap column in the sysusages table
holds the information about which segments map onto each device.
The stored procedure has been kept simple so that users can run it
even in new systems to which they have not yet migrated user
databases. The syntax is:
execute sp_segmap <segmap value>
execute sp_segmap 7
use master
go
if exists (select * from sysobjects
where name = 'sp_segmap')
drop procedure sp_segmap
go
create procedure sp_segmap
@segmap int
as
create table #seg
(segment_num int NULL)
declare @segnum int
declare @pattern int
select @segnum = 0
select @pattern = 1
if @segmap = 0
/* no segments mapped */
begin
insert #seg values(NULL)
select * from #seg
order by segment_num
return
end
while (@segnum < 30)
begin
if (@segmap & @pattern) != 0
insert #seg values(@segnum)
select @pattern = @pattern * 2
select @segnum = @segnum + 1
end
/* Test final bit in @pattern */
if (@segmap & @pattern) != 0
insert #seg values(@segnum)
/* Test if segment 31 bit on */
if @segmap <= -1
insert #seg values(31)
select * from #seg
order by segment_num
go
grant execute on sp_segmap to public
go
Run segmap.sql in isql as the sa user:
isql /Usa /P<password> /S<server> /e /isegmap.sql /osegmap.sql
Additional query words: segments Transact_SQL Windows NT
Keywords : kbprg SSrvAdmin SSrvWinNT
Version : 4.2 | 4.2
Platform : OS/2 WINDOWS
Issue type :
Last Reviewed: March 17, 1999