dbo.QBM_FGITableSizeMB
Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB
Interpretation
- Database function. Usually supports views, validation, or calculated predicates; look at referenced-by entries for callers.
Relations
- No extracted relations.
Typed Edges
- No typed edges extracted for this source.
Complete Source
1CREATE FUNCTION dbo.QBM_FGITableSizeMB(2 @TableName varchar(30),3 @IncludeIndexes BIT4) RETURNS float5AS6BEGIN7 DECLARE @erg float = 0.08 DECLARE @id int = NULL9 DECLARE @PKIndexId int = NULL10 DECLARE @Scanmode varchar(16) = 'SAMPLED'11 SELECT TOP 1 @id = o.object_id12 FROM sys.tables o13 WHERE14 o.name = @TableName15 IF @IncludeIndexes = 016 BEGIN17 SELECT TOP 1 @PKIndexId = i.index_id18 FROM sys.indexes i19 WHERE20 i.object_id = @id AND i.is_primary_key = 121 END22 IF @id IS NOT NULL23 BEGIN24 SELECT @erg =(sum(i.page_count) * 8.192) / 1024.025 FROM sys.dm_db_index_physical_stats(db_id(DB_NAME()),26 @id,27 @PKIndexId,28 NULL,29 @Scanmode) i30 GROUP BY i.object_id31 END32 endLabel:33 RETURN(@erg)34END
Open raw exported source
1 create function dbo.QBM_FGITableSizeMB(@TableName varchar(30) , @IncludeIndexes bit ) returns float as begin declare @erg float = 0.0 declare2 @id int = null declare @PKIndexId int = null declare @Scanmode varchar(16) = 'SAMPLED' select top 1 @id = o.object_id from sys.tables o where o.name 3= @TableName if @IncludeIndexes = 0 begin select top 1 @PKIndexId = i.index_id from sys.indexes i where i.object_id = @id and i.is_primary_key = 1 end 4if @id is not null begin select @erg = (sum(i.page_count) * 8.192) / 1024.0 from sys.dm_db_index_physical_stats(db_id(DB_NAME()), @id, @PKIndexId, null5, @Scanmode) i group by i.object_id end endLabel: return(@erg) end 6