Names and data types
Identifiers, schemas and the SQL Server data types and how each is stored.
Names#
[x]and"x"are identifiers;N'..'strings;0x1FbecomesX'1F'.- Names of tables and databases are not case sensitive in T-SQL but are in the engine: they are lower-cased for the engine. The name as written is kept (in the front-end's table
__mssql_tbl) and shown bysys.tablesandINFORMATION_SCHEMA. - Schemas:
dbo.tist. Another schemas.tbecomes the tables__t(a name prefix).CREATE SCHEMA sis accepted and recorded for the session (CREATE SCHEMAofdbo,sys,guest,INFORMATION_SCHEMAis error 2714);DROP SCHEMAforgets it.db.dbo.tanddb..tare the tabletin the databasedb. A four-part name loses its server part. #tis a temporary table of the session (an engine temporary table);##tis the same (it is not visible to other sessions).
Data types#
| T-SQL | engine column | wire type of an answer |
|---|---|---|
int, bigint, smallint | same | same |
tinyint | tinyint unsigned | tinyint |
bit | tinyint(1) | bit |
decimal(p,s), numeric | decimal(p,s) (default 18,0) | same |
money, smallmoney | decimal(19,4), decimal(10,4) | money, smallmoney |
float, real | double, float | same |
char(n), nchar(n) | char(n) | same (values padded to n) |
| `varchar(n | max), nvarchar(n | max)` |
text, ntext, xml | longtext | varchar(max), nvarchar(max), xml |
binary(n), `varbinary(n | max)` | binary, varbinary, longblob |
date, time(n) | date, time(min(n,6)) | same |
datetime, smalldatetime | datetime(3), datetime(0) | same |
datetime2(n) | datetime(min(n,6)) | datetime2(n) (the 7th digit is 0) |
datetimeoffset | varchar(40) | datetimeoffset (offset +00:00) |
uniqueidentifier | char(36) | same (upper case) |
sql_variant | longtext holding type<SOH>value | sql_variant (the value with its base type) |
The declared type of every column is kept by the front-end in its own tables __mssql_cols and __mssql_tbl of the database (the engine keeps no column comments), and the answers of SELECT, sys.columns and INFORMATION_SCHEMA.COLUMNS are typed from them. Tables made by another front-end are typed from the engine's types.