Data types for ANSI SQL
This topic provides reference content about data type compatibility when migrating from Microsoft SQL Server 2019 to Amazon Aurora MySQL. You can use this information to understand how different data types in SQL Server map to their counterparts in Aurora MySQL.
Feature compatibility | AWS SCT / AWS DMS automation level | AWS SCT action code index | Key differences |
---|---|---|---|
|
|
Minor syntax and handling differences. No special |
SQL Server Usage
In SQL Server, each table column, variable, expression, and parameter has an associated data type.
SQL Server provides a rich set of built-in data types as summarized in the following table.
Category | Data Types |
---|---|
Numeric |
|
String and character |
|
Temporal |
|
Binary |
|
Large Object (LOB) |
|
Cursor |
|
GUID |
|
Hierarchical identifier |
|
Spatial |
|
Sets (table type) |
|
XML |
|
Other specialty types |
|
Note
You can create custom user-defined data types using T-SQL, and the .NET framework. Custom data types are based on the built-in system data types and are used to simplify development. For more information, see User-Defined Types.
TEXT, NTEXT, and IMAGE Deprecated Data Types
The TEXT
, NTEXT
, and IMAGE
data types have been deprecated as of SQL Server 2008 R2. For more information, see Deprecated Database Engine Features in SQL Server 2008 R2
These data types are legacy types for storing BLOB
and CLOB
data. The TEXT
data type was used to store ASCII text CLOBS
, the NTEXT
data type to store UNICODE CLOBS
, and IMAGE
was used as a generic data type for storing all BLOB
data. In SQL Server 2005, Microsoft introduced the new and improved VARCHAR (MAX)
, NVARCHAR(MAX)
, and VARBINARY(MAX)
data types as the new BLOB
and CLOB
standard. These new types support a wider range of functions and operations. They also provide enhanced performance over the legacy types.
If your code uses TEXT
, NTEXT
, or IMAGE
data types, AWS SCT automatically converts them to the appropriate Amazon Aurora MySQL-Compatible Edition (Aurora MySQL) BLOB
data type. TEXT
and NTEXT
are converted to LONGTEXT
and image to LONGBLOB
. Make sure you use the proper collations. For more details, see the Collations.
Examples
Define table columns.
CREATE TABLE MyTable ( Col1 AS INTEGER NOT NULL PRIMARY KEY, Col2 AS NVARCHAR(100) NOT NULL );
Define variable types.
DECLARE @MyXMLType AS XML, @MyTemporalType AS DATETIME2
DECLARE @MyTableType AS TABLE ( Col1 AS BINARY(16) NOT NULL PRIMARY KEY, Col2 AS XML NULL );
For more information, see Data types (Transact-SQL)
MySQL Usage
Amazon Aurora MySQL-Compatible Edition (Aurora MySQL) supports the following data types:
Category | Data Types |
---|---|
Numeric |
|
String and character |
|
Temporal |
|
Binary |
|
Large Object (LOB) |
|
Cursor |
|
Spatial |
|
JSON |
|
Be aware that Aurora MySQL uses different rules than SQL Server for handling out-of-range and overflow situations. SQL Server always raises an error for out-of-range values. Aurora MySQL exhibits different behavior depending on run time settings.
For example, a value may be clipped to the first or last value in the range of permitted values for the data type if STRICT SQL
mode isn’t set.
For more information, see Out-of-Range and Overflow Handling
Converting from TEXT, NTEXT, and IMAGE SQL Server Deprecated Data Types
The legacy SQL Server types for storing LOB data are deprecated as of SQL Server 2008 R2.
When you convert from these types to Aurora MySQL using the AWS Schema Conversion Tool (AWS SCT, they are converted as shown following:
SQL Server LOB Type | Converted to Aurora MySQL data type | Comments |
---|---|---|
|
|
Make sure to choose the right collation. For more information, see Collations. |
|
|
Make sure to choose the right collation. For more information, see Collations. |
|
|
The size cap for all of these types is compatible and is capped at 2 GB of data, which may allow less characters depending on the chosen collation.
Note
Aurora MySQL supports UCS-2 collation, which is compatible with SQL Server UNICODE
types.
While it is safe to use the default conversion types, remember that, unlike SQL Server, Aurora MySQL also provides smaller BLOB
and CLOB
types, which may be more efficient for your data.
Even the basic VARCHAR and VARBINARY data types can store strings up to 32 KB, which is much longer than SQL Server 8 KB limit. If the strings or binary data that you need to store don’t exceed 32 KB, it may be more efficient to store these as non-LOB types in Aurora MySQL.
Summary
The following table summarizes the key differences and migration considerations for migrating from SQL Server data types to Aurora MySQL data types.
SQL Server Data Type | Convert to MySQL Data Type | Comments |
---|---|---|
|
|
Aurora MySQL also supports For more information, see Bit-Value Type - BIT |
|
|
SQL Server only supports unsigned For more information, see Integer Types (Exact Value) |
|
|
Compatible type. SQL Server supports only signed For more information, see Integer Types (Exact Value) |
|
|
Compatible type. SQL Server supports only signed
Aurora MySQL also supports a For more information, see Integer Types (Exact Value) |
|
|
Compatible type. SQL Server supports only signed For more information, see Integer Types (Exact Value) |
|
|
Compatible types. DECIMAL and NUMERIC are synonymous. |
|
N/A |
Aurora MySQL doesn’t support dedicated monetary types. Use |
|
|
Compatible types. In SQL Server, both The Aurora MySQL
Aurora MySQL also supports the nonstandard For more information, see Floating-Point Types (Approximate Value) |
|
|
Compatible types up to 255 characters only. SQL Server supports For strings requiring more than 255 characters, use For more information, see The CHAR and VARCHAR Types |
|
|
Compatible types. SQL Server supports For more information, see The CHAR and VARCHAR Types |
|
|
Aurora MySQL doesn’t require the use of specific data types for storing For more information, see Unicode Character Sets |
|
|
Aurora MySQL doesn’t require the use of specific data types for storing For more information, see Unicode Character Sets |
|
|
Compatible types. The range for SQL Server Aurora MySQL doesn’t support dates before 1000 AD. For more information, see Date and Time Functions. For more information, see The DATE, DATETIME, and TIMESTAMP Types |
|
|
Compatible types. SQL Server supports explicit fractional seconds using the format Aurora MySQL supports up to 6 digits for microsecond resolution of fractional seconds. SQL Server provides one more digit to support a resolution of up to 100 nanoseconds. If your application uses the
Aurora MySQL also supports For more information, see The TIME Type |
|
|
Aurora MySQL doesn’t support For more information, see Date and Time Functions. |
|
|
In SQL Server, the For more information, see Date and Time Functions. For more information about |
|
|
In SQL Server, the For more information, see Date and Time Functions. For more information about |
|
|
Aurora MySQL doesn’t support full time zone awareness and management functions. Use the For more information, see Server Options. In Aurora MySQL, With Aurora MySQL
Aurora MySQL converts For more information, see MySQL Server Time Zone Support |
|
|
In Aurora MySQL, the SQL Server supports up to 8,000 bytes for a Literal assignment for Aurora MySQL
For more information, see The BINARY and VARBINARY Types |
|
|
In Aurora MySQL, the
Aurora MySQL
For more information, see The BINARY and VARBINARY Types |
|
|
In SQL Server, a Use the following list to determine the optimal Aurora MySQL data type:
For more information, see The BLOB and TEXT Types |
|
|
Aurora MySQL doesn’t require the use of specific data types for storing For more information, see Unicode Character Sets |
|
|
In SQL Server, an Similar to the Use the following list to determine the optimal Aurora MySQL data type:
For more information, see The BLOB and TEXT Types |
|
|
Types are compatible, although in Aurora MySQL a cursor isn’t really considered to be a type. For more information, see Cursors. |
|
N/A |
Aurora MySQL doesn’t support a native unique identifier type. Use UUID returns a Universal Unique Identifier generated according to RFC 4122. For more information, see A Universally Unique IDentifier (UUID) URN Namespace For more information, see UUID() |
|
N/A |
Aurora MySQL doesn’t support native hierarchy representation. Rewrite functionality with custom application code using one the common SQL hierarchical data representation approaches:
For more information, see Adjacency list |
|
|
In SQL Server, the
Aurora MySQL supports For more information, see Spatial Data Types |
|
N/A |
Aurora MySQL doesn’t support a |
|
N/A |
Aurora MySQL doesn’t support a native XML data type. However, it does provide full support for JSON data types, which SQL Server doesn’t. Because XML and JSON are text documents, consider migrating the XML formatted documents to JSON or use string BLOBs and custom code to parse and query documents. For more information, see The JSON Data Type |
|
N/A |
Aurora MySQL doesn’t support a row version. Use triggers to update a dedicated column from a primary sequence value table. |
|
N/A |
Aurora MySQL doesn’t support a hybrid, all-purpose data type similar to |
For more information, see Data Types