Posts

Showing posts with the label size

Migrate SQLPrompt Snippets to VSCode

 I love snippets; love em. And I have a whole bunch in RedGate SQL Prompt. Now I want to be able to use those in VSCode as well, but boy do I dread having to retype all of them. Solution? Python! First arg is the path where your SQLPrompt snippets are Second arg is the directory where you want it to spit out a "sql.json" file with all your snippets. """ A script to translate sqlprompt snippet files to vscode formatted snippets """ import os import json import glob import io import argparse class SQLPromptPlaceholder :     """Represents the values of a SQLPrompt placeholder"""     def __init__ ( self , name , default_value ):         self . name = name         self . default_value = default_value class SQLPromptSnippet :     """Represents the content of a SQLPrompt snippet"""     @ staticmethod     def from_file ( filename ):         """Generates an instance fr...

SQL Script: Size of all tables on all databases

Image
Sometimes I get emails from dbas saying our database is filling up and I want to know where the biggest problems are. I'm sure there are some DBA tools to help with that, but I find a really quick easy way is to execute sp_executesql for every table in every database. Here's a script you can run to  get all table sizes on all databases . It basically loops over all database (except those you don't care about, e.g. master, msdn, etc.) and gets the table sizes for each table. At the end, you can then aggregate things by database, or drill into a specific database for table-level details. set nocount, xact_abort on declare @ExclDatabases nvarchar( max ) = 'master|msdb|tempdb|ssisdb|model' , @Schemas nvarchar( max ) = null drop table if exists #AllTabs create table #AllTabs ( DbName nvarchar(128), SchemaName nvarchar(128), TableName nvarchar(128), ObjectId int, RowCt bigint, ReservedKB bigint, DataKB bigint, IndexSizeKB...

Database Size Script

This just executes sp_spaceused on every table in a database, and plops the results into a temp table so you can query the data altogether. declare @TableName varchar(128), @RID int, @MaxRID int, @SQL nvarchar(max) if object_id('tempdb.dbo.#LoopSrc') is not null drop table #LoopSrc create table #LoopSrc ( RID int identity(1,1) primary key clustered, TableName varchar(128) ) if object_id('tempdb.dbo.#Tabs') is not null drop table #Tabs create table #Tabs ( TableName varchar(128), nRows int, nReserved as cast(replace(sReserved, ' KB', '') as int), nData as cast(replace(sData, ' KB', '') as int), nIndexSize as cast(replace(sIndexSize, ' KB', '') as int), nUnused as cast(replace(sUnused, ' KB', '') as int), sReserved varchar(30), sData varchar(30), sIndexSize varchar(30), sUnused varchar(30) ) /***************************** *** INSERT LOOP ITEMS...