Jerry Nixon @Work: Utility scripts for SQL tables

Jerry Nixon on Windows

Wednesday, April 28, 2021

Utility scripts for SQL tables

The SQL Server sys.tables & sys.schemas tables are exceptionally handy to find & filter tables in the database. Quickly looping through a list of table commands to execute a delete, truncate, drop, update, disable constraint, enable constraint, or require data script is easy – just use a while loop, a cursor, or print the results to use in a larger script you are writing. Truth is, this little snippet helps you query for the tables, their schema and the boilerplate script syntax. I’ve used scripts just like this for years.

image

Here it is on GitHub: link.