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 query with PATH Item, ROOT Catalog, Price as an attribute and SeedName as text, beside the XML it returns: a Catalog root with four Item elements, each holding a Price attribute and a seed name

XML Element Names in SQL Server: Row, Root and Text With FOR XML PATH

September 1, 2011
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Server, SQL String, SQL XML

XML element names in SQL Server come from your query, and FOR XML PATH lets you choose them. This post sets the row and root names, turns a column into an attribute, writes text inside an element and shows the error you get when an attribute column comes too late. Every result comes from SQL Server 2025.

Read More
Seven books on three shelves as XML: ordered by BookID the Shelf element repeats seven times, with Gardening, Travel and Cooking coming back again and again, while ordered by Section and Title there are only three Shelf elements holding two or three books each

FOR XML AUTO in SQL Server: Nest Joined Rows and Name the Root

August 31, 2011
Pinal Dave
SQL Tips and Tricks
SQL Joins, SQL Scripts, SQL Server, SQL XML

FOR XML AUTO turns a join into nested XML, with one element per table. This post shows where the element names come from, why row order decides the grouping, how ROOT adds a single root, and how the order of your columns flips the nesting. Every result comes from SQL Server 2025.

Read More
One borrower whose BranchID is NULL shown three ways: RAW writes three attributes and no BranchID, RAW with ELEMENTS writes three child elements, and ELEMENTS XSINIL writes four with BranchID marked xsi:nil true

FOR XML RAW in SQL Server: Row Names, ROOT, ELEMENTS and NULLs

August 30, 2011
Pinal Dave
SQL Tips and Tricks
SQL NULL, SQL Scripts, SQL Server, SQL XML

FOR XML RAW turns each row of a query into an XML element. This post names the row element, adds a ROOT, switches to ELEMENTS and shows how a NULL value drops out of the output until XSINIL puts it back. Every result comes from SQL Server 2025.

Read More
A cord passes through one reinforced brass opening in an intact canvas panel

EXECUTE AS OWNER in Stored Procedures: Power and Pitfalls

August 29, 2011
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Server, SQL Server Security

A procedure with owner rights can write to tables its caller cannot touch. Watch the identity change, and see how one careless parameter hands out too much.

Read More
A grid of four plants with its column names in one red header, beside the same rows as XML where PlantID, PlantName, Light and WaterDays repeat inside every row element

What Is XML in SQL Server: Tags, Attributes and Well-Formed Rules

August 29, 2011
Pinal Dave
SQL Tips and Tricks
SQL Datatype, SQL Scripts, SQL Server, SQL XML

What is XML in SQL Server? It’s plain text where every value carries its own label. This post turns four plant rows into XML with FOR XML RAW, names the parts of a document, and shows the errors SQL Server returns when a rule is broken.

Read More
A grid of two cases: when Plan A works the UPDATE runs, Plan A worked is printed and CATCH is skipped; when Plan A fails the UPDATE raises error 515, the rest of TRY is skipped and CATCH prints Plan B with error 515, severity 16, line 2

TRY CATCH Block in SQL Server: Plan A, Plan B and the Rollback

August 28, 2011
Pinal Dave
SQL Tips and Tricks
SQL Error Messages, SQL Scripts, SQL Server, SQL Transactions

A TRY CATCH block runs Plan A and falls back to Plan B when Plan A raises an error. This post shows that CATCH runs only after an error, that severity 11 is the line between a message and an error, and that one ROLLBACK undoes a nested transaction completely. Every result comes from SQL Server 2025.

Read More
Two columns of messages: errors SQL Server raises itself, 2714 and 515 at level 16 and 3701 at level 11, and errors you raise yourself with RAISERROR and THROW, 50000 and 50001 at level 16, plus a severity 10 note that is only a message

Raise Your Own Error in SQL Server: When Valid Code Breaks a Rule

August 27, 2011
Pinal Dave
SQL Tips and Tricks
SQL Error Messages, SQL Scripts, SQL Server, SQL Stored Procedure

Raise your own error in SQL Server when a valid statement breaks a rule you care about. This post shows three errors SQL Server raises itself, one error that depends on what exists in the database, and how RAISERROR and THROW turn an update of zero rows into a clear message. Every result comes from SQL Server 2025.

Read More
Previous 1 … 308 309 310 311 312 313 314 … 416 Next
  • Books
  • Testimonials
  • Privacy Policy

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