SQL Server front-end (T-SQL)

T-SQL: stage 9

What stage 9 (D146) built - hierarchyid, more geometry and geography methods, the catalog answers tools read, MERGE TOP with BY SOURCE, binary shifts, defaults of existing columns, implicit transactions, TLS settings - and what is decided out of scope.

This page lists what stage 9 (D146) added to the SQL Server front-end and what it leaves refused.

hierarchyid#

  • The type: columns, variables, parameters (the CLR type SqlHierarchyId on the wire, which .NET reads as a SqlHierarchyId), keys and indexes. A value is kept in the OrdPath byte encoding, so tables keyed by hierarchyid sort depth first.
  • Methods: hierarchyid::GetRoot(), hierarchyid::Parse(), ToString(), GetLevel(), GetAncestor(n), GetDescendant(c1, c2), IsDescendantOf(), GetReparentedValue(); CAST to and from text and varbinary; text such as '/1/2/' converts to it in INSERT, UPDATE, comparisons and method arguments.
  • Errors: 6522 (with the numbers 24001, 24007, 24008, 24009, 24011), 403, 529. sys.types, sys.columns and INFORMATION_SCHEMA list the type. A computed column may be written without parentheses (lvl AS node.GetLevel() PERSISTED).
  • Read / Write are not callable from T-SQL.

geometry and geography#

  • Built: STConvexHull, STIsValid and IsValidDetailed (24400, 24404, 24406, 24411, 24413), STBoundary, STIsSimple, MakeValid of a valid shape, Reduce of polygons, STBuffer / BufferWithTolerance of points; geography STDistance and STLength on the WGS 84 ellipsoid and STArea on the authalic sphere.
  • Refused (error 40000): STUnion, STIntersection, STDifference, STSymDifference (they were listed as supported before, but were not), STBuffer of lines and polygons, MakeValid of an invalid shape, geography buffers and hulls.

Catalog and tools#

sys.check_constraints, sys.computed_columns, sys.default_constraints and INFORMATION_SCHEMA.COLUMNS show definitions in SQL Server's stored form (([amount]>=(0)), ((1)), (getdate())); INCLUDE columns of an index; default constraints in sys.objects; sp_helpconstraint, sp_helpuser, sp_statistics, sp_sproc_columns, sp_sproc_columns_100, sp_columns_100 in SQL Server's layout.

Statements and functions#

  • MERGE TOP (n) with WHEN NOT MATCHED BY SOURCE (rows taken in the order of the ON key; the ON condition needs an equality of a target and a source column); @@ROWCOUNT after MERGE with NOCOUNT ON.
  • ALTER TABLE .. ADD [CONSTRAINT ..] DEFAULT expr FOR column with any expression (getutcdate(), newid(), NEWSEQUENTIALID()), and DROP CONSTRAINT of a named default. An IDENTITY seed other than 1 is kept.
  • << / >> / LEFT_SHIFT / RIGHT_SHIFT of binary and varbinary values; CAST between whole numbers and binary; datetime - datetime; UPPER / LOWER change one character for one; error 8127 for ORDER BY of a column that is not grouped.
  • CONVERT of text to a date with styles 22, 130 and 131.
  • SET IMPLICIT_TRANSACTIONS ON (what JDBC and ODBC drivers send when auto-commit is off): a statement that reads or changes a table opens a transaction.
  • Forms seen in real scripts: comparisons written with a blank (! =, < =), old table hints (t (NOLOCK)), hints on the target of UPDATE / DELETE, a function without AS, TOP in a UNION branch, FOR XML PATH('') to concatenate text, a CTE before INSERT, sp_rename of a column, sp_MSforeachtable.

Connections#

raftdb-mssql takes --ssl auto (a generated certificate), --ssl-cert FILE --ssl-key FILE and --ssl-mode login|preferred|required; a client that asks for encryption gets the whole connection under TLS, and sys.dm_exec_connections.encrypt_option says TRUE.

Server level#

sp_configure (read), DBCC USEROPTIONS / OPENTRAN / CHECKIDENT / CHECKTABLE / CHECKDB, the fixed server roles, IS_SRVROLEMEMBER, SUSER_SID answer in SQL Server's layout. SQL Server Agent jobs run inside Raft DB (see stage 6); the msdb tables do not have every column SQL Server's have.

Out of scope#

CLR (assemblies: error 6263), Service Broker, Always Encrypted keys, replication, SSIS and linked servers are not part of the front-end. They are refused with the numbers SQL Server gives on a server where none of them is set up: 7202 for OPENQUERY, four-part names and EXEC .. AT; 8426 for SEND; 208 for RECEIVE and BEGIN DIALOG; 15151 for OPEN SYMMETRIC KEY; 15281 for OPENROWSET / OPENDATASOURCE; 15010 for sp_replicationdboption of a database that does not exist; 40000 for the linked-server and replication procedures.