sql server - SQL function to return the number or records in a given table -
i want create simple function in sql takes table name input , return number of records table.
how can create such 'dynamic' function?
ahh not have use dynamic sql this. can instead use table partitions.
this should work you. 1 caveate is possible may not 100% accurate have never seen not correct. according documentation "approximate number of rows in partition".
create function gettablerowcount ( @tablename sysname ) returns table return select sum(row_count) myrowcount sys.dm_db_partition_stats object_id = object_id(@tablename) group object_name(object_id); this inline table valued function instead of more common scalar function.
Comments
Post a Comment