SQL Server emergency? Email pinal@sqlauthority.com with URGENT in the subject line.

Add an XML Column to a Table: One Row, Many Related Values

To add an XML column to a table, use ALTER TABLE with the xml data type, and each row can then carry a list of related values. This post adds a Labels column to a Recipes table, fills it, checks that bad XML is refused, and asks questions with value() and exist(). It then builds the same data as a child table and compares what each design can enforce. Every result comes from SQL Server 2025.

Continue Reading

Run a String as SQL: EXEC, Parameters and Four Traps

To run a string as SQL, you pass it to EXEC or to sp_executesql, and SQL Server runs the text as a statement. This post builds a string from pieces, shows why EXEC cannot take parameters, and adds them with sp_executesql. It also shows four traps: a variable the string cannot see, a NULL that empties the string, a variable that is too short, and a function that cannot run a string. Every result comes from SQL Server 2025.

Continue Reading

Introduction to GUIDs: Merge Tables Without Key Clashes

An introduction to GUIDs starts with one problem: two tables that both count from 1. This post merges two small shop tables, first with INT keys and then with UNIQUEIDENTIFIER keys, and shows how to create, read and sort GUIDs. It also answers common reader questions: adding GUIDs, finding the newest row and getting the new key back. Every result comes from SQL Server 2025.

Continue Reading