I recently saw a comment from @Larnu highlighting that 3 part naming on columns will soon(ish) be depreciated. There was a link to a useful article on his website which details about this:
https://wp.larnu.uk/3-part-naming-on-columns-will-be-deprecated/
Specifically, it quotes from the depreciated SQL Server features page on docs.microsoft.com (https://docs.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2016?view=sql-server-ver15):
The following SQL Server Database Engine features are supported in the next version of SQL Server, but will be deprecated in a later version. The specific version of SQL Server has not been determined:
Category Deprecated feature Replacement Feature name Feature ID Transact-SQL Three-part and four-part column references. Two-part names is the standard-compliant behavior. More than two-part column name 3
My question is does this apply to when using XMLnodes as a column reference? e.g.:
SELECT
XMLNodes.x.value('@time', 'datetime') as Runtime,
InnerXMLNode.x.value('@currency', 'varchar(3)') as Currency,
InnerXMLNode.x.value('@rate', 'Decimal(10,7)') as Rate
from
@xmlFile.nodes('/Envelope/Cube/Cube') as XMLNodes(x)
cross apply XMLNodes.x.nodes('Cube') as InnerXMLNode(x)
I can't find anything specifically excluding XMLnodes, but are they technically still columns? If the depreciated feature does include XMLnodes, how do you do this without 3 part naming?
CodePudding user response:
No, it is not. It is just invoking a method on that column.
For example, you can also do
CAST(SomeValue AS xml).value(.....
and clearly that is not three-part naming
The official grammar for SELECT
is as follows
<select_list> ::=
{
*
| { table_name | view_name | table_alias }.*
| {
[ { table_name | view_name | table_alias }. ]
{ column_name | $IDENTITY | $ROWGUID }
| udt_column_name [ { . | :: } { { property_name | field_name }
| method_name ( argument [ ,...n] ) } ]
| expression
[ [ AS ] column_alias ]
}
| column_alias = expression
} [ ,...n ]
and although the grammar is not perfect, you can see that udt_column_name.method_name
is not classed as an extra column name.
CodePudding user response:
No, the 3 part naming means when you are naming the object names, for example SchemaName.TableName.ColumnName
, that isn't the case in the above.
XMLNodes
is the table name, and x
the column, however, value
is a method of the xml
type (basically a function), not an object. So you are using 2 part naming, and then using a method extension of the xml
type, just like you are in the FROM
for nodes
(XMLNodes.x.nodes
).