Skip to content

Instantly share code, notes, and snippets.

@arnabdas
Created October 2, 2018 07:24
Show Gist options
  • Save arnabdas/34095d32c8f0e5b54a12f64a5fa01298 to your computer and use it in GitHub Desktop.
Save arnabdas/34095d32c8f0e5b54a12f64a5fa01298 to your computer and use it in GitHub Desktop.
Useful tsql scripts taken from around the net
-- Get the sp text
DECLARE @Lines TABLE (Line NVARCHAR(MAX)) ;
DECLARE @FullText NVARCHAR(MAX) = '' ;
INSERT @Lines EXEC sp_helptext 'sp_ProcedureName' ;
SELECT @FullText = @FullText + Line FROM @Lines ;
PRINT @FullText ;
-- Get db and table sizes
select
sum(reserved_page_count) * 8.0 / 1024 [SizeInMB]
from
sys.dm_db_partition_stats
GO
select
sys.objects.name, sum(reserved_page_count) * 8.0 / 1024 [SizeInMB]
from
sys.dm_db_partition_stats, sys.objects
where
sys.dm_db_partition_stats.object_id = sys.objects.object_id
group by sys.objects.name
order by sum(reserved_page_count) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment