FOR


The FOR clause is used to specify either the BROWSE or the unrelated XML option. The FOR syntax is as follows:

  [ FOR { BROWSE | XML { RAW | AUTO | EXPLICIT } [ , XMLDATA ] [ , ELEMENTS ] [ , BINARY BASE64 ] } ]

See Chapter 17 for the complete lowdown on the XML support in SQL Server 2005.

BROWSE

The BROWSE argument specifies that updates are possible while viewing data in a DB-Library browse-mode cursor. A table can be browsed in an application if the table includes a time-stamped column (defined with the timestamp data type), the table has a unique index, and the FOR BROWSE option is at the end of the SELECT statement(s) sent to SQL Server. You also cannot use the FOR BROWSE option in SELECT statements that are joined by the UNION operator.

FOR XML

FOR XML specifies that the results of a query are to be returned as an XML document. One of these XML modes must be specified: RAW, AUTO, EXPLICIT. XML support in SQL Server 2005 is discussed in depth in Chapter 17.

RAW

The RAW mode takes the query result and transforms each row in the result set into an XML element with a generic identifier <row /> as the element tag (see Chapter 17).

AUTO

The AUTO mode returns query results in a simple, nested XML tree. Each table in the FROM clause for which at least one column is listed in the SELECT clause is represented as an XML element. The columns listed in the SELECT clause are mapped to the appropriate element attributes.

EXPLICIT

The EXPLICIT mode specifies that the shape of the resulting XML tree is defined explicitly. Using this mode, queries must be written in a particular way so that additional information about the desired nesting is specified explicitly.

XML Parameters

The following XML parameters specify the type of data returned in the XML result set:

  • XMLDATA   A parameter that returns the schema but does not add the root element to the result. If XMLDATA is specified, it is appended to the document (see Chapter 17).

  • ELEMENTS   Specifies that the columns are returned as subelements. Otherwise, they are mapped to XML attributes.

  • BINARY BASE64   Specifies that the query returns the binary data in binary base 64-encoded format. In retrieving binary data using RAW and EXPLICIT mode, this option must be specified. This is the default in AUTO mode.




Microsoft SQL Server 2005. The Complete Reference
Microsoft SQL Server 2005: The Complete Reference: Full Coverage of all New and Improved Features
ISBN: 0072261528
EAN: 2147483647
Year: 2006
Pages: 239

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net