預設包含 NULL 值的資料行Columns that Contain a Null Value By Default
適用範圍:Applies to: SQL ServerSQL Server (所有支援的版本)
SQL ServerSQL Server (all supported versions)
Azure SQL DatabaseAzure SQL Database
Azure SQL DatabaseAzure SQL Database適用範圍:Applies to:
SQL ServerSQL Server (所有支援的版本)
SQL ServerSQL Server (all supported versions)
Azure SQL DatabaseAzure SQL Database
Azure SQL DatabaseAzure SQL Database
依預設,資料行中的 Null 值會與缺少的屬性、節點或元素相對應。By default, a null value in a column maps to the absence of the attribute, node, or element. 此預設行為可使用 ELEMENTS XSINIL 關鍵字片語覆寫。This default behavior can be overridden by using the ELEMENTS XSINIL keyword phrase. 此片語會要求項目中心 XML。This phrase requests element-centric XML. 這表示傳回的結果中會明確指出 Null 值。This means that null values are explicitly indicated in the returned results. 這些項目將不具有任何值。These elements will have no value.
下列 Transact-SQL SELECT 範例中會顯示 ELEMENTS XSINIL 片語。The ELEMENTS XSINIL phrase is shown in the following Transact-SQL SELECT example.
SELECT EmployeeID as "@EmpID",
FirstName as "EmpName/First",
MiddleName as "EmpName/Middle",
LastName as "EmpName/Last"
FROM HumanResources.Employee E, Person.Contact C
WHERE E.EmployeeID = C.ContactID
AND E.EmployeeID=1
FOR XML PATH, ELEMENTS XSINIL;
下列範例會顯示結果。The following shows the result. 請注意如果沒有指定 XSINIL,將不會有 <Middle
> 元素。Note that if XSINIL is not specified, the <Middle
> element will be absent.
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" EmpID="1">
<EmpName>
<First>Gustavo</First>
<Middle xsi:nil="true" />
<Last>Achong</Last>
</EmpName>
</row>