A query to find the biggest table in database: it lists row count, column count and data size for each table using sp_spaceused, sorted by data size.
SQL SERVER – Simple Example of Cursor
The simple example of cursor I have used for years: declare it, open it, fetch each Account_ID in a WHILE loop, then close and deallocate the cursor.
SQL SERVER – Shrinking Truncate Log File – Log Full
The old code I used to truncate log file space with DBCC SHRINKFILE and BACKUP LOG WITH TRUNCATE_ONLY. It breaks the log chain, so take a full backup after.
SQL SERVER – Find Stored Procedure Related to Table in Database – Search in All Stored Procedure
Two quick queries on syscomments to find every stored procedure related to table names you search for, since sp_help and sp_depends are not always accurate.
SQL SERVER – Cursor to Kill All Process in Database
A simple cursor to kill all process connections in one database. It reads sp_who into a temp table and runs KILL for each spid. Run it from another database.
SQL SERVER – Simple Cursor to Select Tables in Database with Static Prefix and Date Created
A simple cursor to select tables in a database by a static prefix like b_ or delete_ and by date created, so you can drop, print or index old tables.







