MySQL to SQL Server Data Type Comparisons

Overview

Unfortunately MySQL and MS SQL Server use slightly different data types, so you will have to do some mapping to get the correct data after the migration. This chapter describes the most important data types in MySQL and their equivalents or recommended migration targets in SQL Server.

Explanation

The following tables show you the mapping of data types for data migration.

Integer

MySQLMS SQL ServerConversion remarks
TINYINTtinyinttinyint is unsigned
SMALLINTsmallint
MEDIUMINTintint stores data on 4 bytes
INT
BIGINTbigint

Decimal

MySQLMS SQL ServerConversion remarks
DECIMAL(M,D)decimal(p,s)The maximum precision is 38, while the default is 18. The default scale is 0.

You can use the float or double data types for decimals with a precision greater than 38.

Floating Point

MySQLMS SQL ServerConversion remarks
FLOAT(N)float(n)
FLOAT(M,D)float(24)SQL Server does not allow the non-standard syntax
DOUBLE(M,D)float(53)SQL Server does not allow the non-standard syntax
REAL(M,D)

Date and Time

MySQLMS SQL ServerConversion remarks
DATETIMEdatetime2Date values start at 0001-01-01
DATEdateDate values start at 0001-01-01
TIMEtimetimerange is 00:00:00.0000000 through 23:59:59.9999999
TIMESTAMPsmalldatetimesmalldatetime value range is 1900-01-01 through 2079-06-06
YEARsmallint

Please note that MS SQL Server cannot store zeros as month or day. You can read more about SQL Server 2008 Date and Time Data Types in this tip.

String

MySQLMS SQL ServerConversion remarks
CHARnchar(n)nchar allows 4000 characters
VARCHARnvarchar(n|max)nvarchar allows 4000 characters but max indicates maximum storage size of 2^31-1 bytes.
TINYTEXT
TEXT(M)
MEDIUMTEXT
LONGTEXT

\’ escape sequences in string constants should be replaced by double quote characters.

Binary

MySQLMS SQL ServerConversion remarks
BINARY(M)binary(n)binary allows 8000 bytes
VARBINARY(M)varbinary(n|max)nvarbinary allows 8000 bytes but max indicates maximum storage size of 2^31-1 bytes.
TINYBLOB
BLOB
MEDIUMBLOB
LONGBLOB

Additional Information

Data Types without MySQL Equivalent

Leave a Reply

Your email address will not be published. Required fields are marked *