Simple Prevent Write Commands In Sql


On multiple occasions, I found myself trying to check if a query for data read is safe to execute or not. This is typically useful when the query is saved outside of your code, and you cannot restrict the access level of the user executing it.

The following regex, while not exhausting by any means, will detect most query patterns typically used to change data. Note that inserts, updates, deletes, and merges are permitted on temporary tables (e.g.: #tbl or ##tbl) and memory tables (e.g.: @tbl).

Cheers, Lucas