This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
A row of small snowmen along a snowy path, each wearing the same red scarf

Running a Command in Every Database Without sp_MSforeachdb

January 5, 2013
Pinal Dave
SQL Tips and Tricks
DBA, Dynamic SQL, SQL Scripts, SQL Server

Run a checked command in every database with a FAST_FORWARD cursor, AG role filter, QUOTENAME, and per-database error log.

Read More
A pepper mill holds peppercorns above its mechanism with an unsuitable pebble caught before grinding

Second-Order SQL Injection: When Stored Data Becomes Code

May 30, 2012
Pinal Dave
SQL Tips and Tricks
Dynamic SQL, SQL Server Security, SQL String, SQL Variable

A safe insert does not make the saved value safe forever. Here is how stored text turns into code later, and the plain fix.

Read More
A pastry crimper seals a pie edge through its fixed toothed shape beside unused decorative cutters

Dynamic ORDER BY Without Injection: Whitelisting Sort Columns

May 9, 2012
Pinal Dave
SQL Tips and Tricks
Dynamic SQL, SQL Order By, SQL Server Security, SQL Variable

Parameters cannot name a column, so grids end up gluing text into SQL. Here is the approved-list pattern that keeps the sort safe.

Read More
A full spice rack with no room left, a new jar of red paprika standing on the counter below

Dynamic PIVOT: Building Report Columns From the Data

May 17, 2009
Pinal Dave
SQL Tips and Tricks
Dynamic SQL, PIVOT and UNPIVOT, SQL Reports, SQL Server

Build a dynamic PIVOT with ordered STRING_AGG and QUOTENAME, parameterized filters, zero-filled results, and explicit report-width limits.

Read More
Gouache painting of a person sorting punctuation into a separate tray beside a database cabinet

SQL Injection: The Joke, the Failure and the Parameter Fix

October 12, 2008
Pinal Dave
SQL Tips and Tricks
Best Practices, Dynamic SQL, SQL Humor, SQL Server Security

SQL Injection makes a good joke and a terrible incident. The tests here show a concatenated query returning every row for one hostile name, the same text passed as a parameter returning none, a table name caught by QUOTENAME, and a read-only user blocked from dropping a table.

Read More
A hand pours red liquid into a copper jelly mold beside two finished jellies of different colors and the same shape.

Parameterized Queries From Application Code

June 29, 2008
Pinal Dave
SQL Tips and Tricks
Best Practices, Developer, Dynamic SQL, SQL Server, SQL Server Security

Use parameterized queries from application code to prevent SQL injection, improve plan reuse, and avoid parameter length mistakes.

Read More
A fingertip presses into a gap in an old stone wall where crumbled mortar lets a green shoot push through.

Finding Dynamic SQL Open to Injection

June 24, 2008
Pinal Dave
SQL Tips and Tricks
Dynamic SQL, SQL Server, SQL Server Security, SQL Stored Procedure

Find dynamic SQL open to injection by searching module definitions for concatenation, then replace data concatenation with parameters.

Read More
Previous 1 2 3 4 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com