Querying the table result in XML format

There are different key words used in the select statement to query the table data in the xml format.



SELECT * FROM products FOR XML AUTO
SELECT * FROM products FOR XML AUTO, TYPE

<products ProductID="1" ProductName="Lenovo" ProductVendor="Lenovo Corporation" />
<products ProductID="2" ProductName="HP Notebook" ProductVendor="Helwelett Packard" />
<products ProductID="3" ProductName="IBM Notebook" ProductVendor="IBM" />
<products ProductID="5" ProductName="DELL" ProductVendor="DELL Corporation India" />

SELECT * FROM products FOR XML AUTO, ELEMENTS

<products>
  <ProductID>1</ProductID>
  <ProductName>Lenovo</ProductName>
  <ProductVendor>Lenovo Corporation</ProductVendor>
</products>
<products>
  <ProductID>2</ProductID>
  <ProductName>HP Notebook</ProductName>
  <ProductVendor>Helwelett Packard</ProductVendor>
</products>
<products>
  <ProductID>3</ProductID>
  <ProductName>IBM Notebook</ProductName>
  <ProductVendor>IBM</ProductVendor>
</products>
<products>
  <ProductID>5</ProductID>
  <ProductName>DELL</ProductName>
  <ProductVendor>DELL Corporation India</ProductVendor>
</products>

SELECT * FROM products FOR XML RAW

<row ProductID="1" ProductName="Lenovo" ProductVendor="Lenovo Corporation" />
<row ProductID="2" ProductName="HP Notebook" ProductVendor="Helwelett Packard" />
<row ProductID="3" ProductName="IBM Notebook" ProductVendor="IBM" />
<row ProductID="5" ProductName="DELL" ProductVendor="DELL Corporation India" />

SELECT * FROM products FOR XML PATH('Product'), ROOT('Products')
<Products>
  <Product>
    <ProductID>1</ProductID>
    <ProductName>Lenovo</ProductName>
    <ProductVendor>Lenovo Corporation</ProductVendor>
  </Product>
  <Product>
    <ProductID>2</ProductID>
    <ProductName>HP Notebook</ProductName>
    <ProductVendor>Helwelett Packard</ProductVendor>
  </Product>
  <Product>
    <ProductID>3</ProductID>
    <ProductName>IBM Notebook</ProductName>
    <ProductVendor>IBM</ProductVendor>
  </Product>
  <Product>
    <ProductID>5</ProductID>
    <ProductName>DELL</ProductName>
    <ProductVendor>DELL Corporation India</ProductVendor>
  </Product>
</Products>