This is an old revision of the document!
SQLines provides tools and services to help you transfer data, convert database schema (DDL), views, stored procedures, functions, triggers, queries and SQL scripts from Microsoft SQL Server to MySQL.
We also help convert embedded SQL statements in C/C++ (ODBC, ESQL/C, DBLIB), C#, Java, PowerBuilder, VB/VB.NET, ASP/ASP.NET and Perl/PHP applications.
SQLines tools to help you migrate from Microsoft SQL Server to MySQL:
SQLines SQL Converter tool allows you to convert database schema (DDL), queries and DML statements, views, stored procedures, functions and triggers from Microsoft SQL Server to MySQL.
SQLines tool converts SQL scripts and standalone SQL statements. To migrate data and database schema from an SQL Server database use SQLines Data tool.
Try SQLines Online or download the Desktop Version.
Technical information on migration from Microsoft SQL Server to MySQL.
Converting SQL language elements from SQL Server to MySQL:
Converting data types from SQL Server to MySQL:
Data type synonyms:
SQL Server Data Type | SQL Server Synonym | MySQL Synonym | |
CHAR | CHARACTER | CHARACTER | |
DECIMAL | DEC | DEC |
Converting functions:
SQL Server | MySQL | ||
1 | CONVERT(DATETIME, string, style) | Convert string to datetime | STR_TO_DATE(string, format) |
2 | CONVERT(VARCHAR, datetime, style) | Convert datetime to string | DATE_FORMAT(datetime, format) |
3 | DATEADD(unit, value, exp) | Add datetime interval | TIMESTAMPADD(unit, value, exp) |
4 | DATEDIFF(units, start, end) | Get datetime difference in specified units | TIMESTAMPDIFF(units, start, end) |
5 | GETDATE() | Get the current date and time | NOW() |
6 | GETUTCDATE() | Get the current UTC date and time | UTC_TIMESTAMP() |
7 | HOST_NAME() | Get the host name | @@HOSTNAME |
8 | ISNULL(exp, replace) | Replace NULL | IFNULL(exp, replace) |
9 | MONTH(datetime) | Extract month from datetime | MONTH(datetime) |
10 | LEFT(string, n) | Return n leftmost characters from string | LEFT(string, n) |
11 | LEN(string) | Length in characters excluding trailing spaces | CHAR_LENGTH(RTRIM(string)) |
12 | NEWID() | Generate GUID | UUID() |
13 | RAISERROR(text, sv, st) | Raise an error | SIGNAL statement |
14 | RIGHT(string, n) | Return n rightmost characters from string | RIGHT(string, n) |
15 | SCOPE_IDENTITY() | Get last identity value | LAST_INSERT_ID() |
16 | STR(float, len, decimal) | Convert float to string | CONVERT(float, CHAR) |
17 | STUFF(str, start, len, new) | Replace substring at start position with new substring | INSERT(str, start, len, new) |
18 | SUSER_NAME() | Get the user name | CURRENT_USER() |
19 | YEAR(datetime) | Extract year from datetime | YEAR(datetime) |
Converting CREATE TABLE statement keywords and clauses:
SQL Server | MySQL | |||
1 | IDENTITY(start, increment) | Identity column | AUTO_INCREMENT | Increment is always 1 |
2 | PRIMARY KEY CLUSTERED | Primary key Constraint | PRIMARY KEY |
Converting SQL queries from SQL Server to MySQL:
SQL Server | MySQL | ||
1 | SELECT @v = c, @v2 = c2 FROM … | SELECT INTO statement | SELECT c, c2 INTO v, v2 FROM … |
Converting Transact-SQL stored procedures from SQL Server to MySQL:
For further information, see Conversion of Transact-SQL Statements.
Converting Transact-SQL user-defined functions from SQL Server to MySQL:
For further information, see Conversion of Transact-SQL Statements.
Converting SET statement for options from SQL Server to MySQL:
SQL Server | MySQL | ||
1 | SET ANSI_NULLS ON | OFF | Use = <> with NULLs | Commented |
2 | SET NOCOUNT ON | OFF | Send messages on affected rows | Removed |
3 | SET QUOTED_IDENTIFIER ON | OFF | Quote identifiers with "" | Commented |
Converting Transact-SQL statements from SQL Server to MySQL:
Variable declaration and assignment:
SQL Server | MySQL | |
1 | DECLARE @var [AS] type [= default_value] | DECLARE var type [DEFAULT default_value] |
2 | DECLARE @v1 type1, @v2 type2, … | DECLARE v1 type1; DECLARE v2 type2, DECLARE … |
3 | DECLARE @tab TABLE | CREATE TEMPORARY TABLE vtab |
4 | SET @var = expression | SET var = expression |
5 | SET @var = (SELECT expression FROM …) | SET var = (SELECT expression FROM …) |
Flow-of-control statements:
SQL Server | MySQL | ||
1 | IF condition BEGIN … END | IF statement | IF condition THEN … END IF; |
2 | IF … ELSE IF … | IF ELSE IF statement | IF … ELSEIF … |
3 | WHILE condition BEGIN stmts END | Conditional loop | WHILE condition DO stmts END WHILE; |
Other Transact-SQL statements:
Converting SQL statements from SQL Server to MySQL:
SQL Server | MySQL | ||
1 | USE dbname | Change the database | USE dbname |