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 emergency? Email pinal@sqlauthority.com with URGENT in the subject line.
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 – Fix : Error 14274: Cannot add, update, or delete a job (or its steps or schedules) that originated from an MSX server. The job was not saved.
Error 14274 shows up when you update or delete SQL Server 2000 jobs after the Windows server was renamed. Here is why it happens and the steps to fix it.
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.
SQL Server slow? Let's fix it together in about four hours.
In my Comprehensive Database Performance Health Check, you share your screen, I guide you, and we fix your biggest performance troublemakers. No passwords. No remote access.
You keep every script, and the know-how to fix it yourself next time.
Want your whole team to learn it?
My Practical Workshop has no PowerPoint, just live demos. My AI Enablement Workshop shows your team where AI saves hours, and where it quietly costs them.
Over 400 customers have worked with me this way, and not one shared a password. See all consulting options.
Who We Are
Pinal Dave is an SQL Server Performance Tuning Expert and independent consultant with over 24 years of hands-on experience. He holds a Masters of Science degree and numerous database certifications.
Pinal has authored 19 books and 125 Pluralsight courses. To freely share his knowledge and help others build their expertise, Pinal has also written more than 5,800 database tech articles on his blog at https://blog.sqlauthority.com.
Pinal is also a CrossFit Level 1 Trainer (CF-L1) and CrossFit Level 2 Trainer (CF-L2).
Nupur Dave is a social media enthusiast and an independent consultant. She primarily focuses on the database domain, helping clients build short and long-term multi-channel campaigns to drive leads for their sales pipeline.
Shaivi Pinalkumar Dave is a book author and a women’s artistic gymnast.

