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 – 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.
SQL SERVER – Auto Generate Script to Delete Deprecated Fields in Current Database
I mark old columns with a dep_ prefix, then auto generate the script to delete deprecated fields and drop their constraints first. Here is the query I use.







