SQL Server MySQL

SQL Server to MySQL Converter: Syntax Guide & Examples

A complete reference for converting SQL Server (T-SQL) queries to MySQL. Covers TOP to LIMIT, IDENTITY to AUTO_INCREMENT, NVARCHAR handling, and every major syntax difference.

Mar 11, 2026 10 min read

Why Convert SQL Server to MySQL?

Teams migrate from SQL Server to MySQL to reduce licensing costs, move to open-source infrastructure, or adopt platforms that run on MySQL such as WordPress, Shopify integrations, or PlanetScale. MySQL is also the default for many cloud-native stacks and has a massive ecosystem of tools and hosting providers.

MySQL's simpler licensing model (GPL or commercial) eliminates per-core or per-CAL costs that SQL Server requires. For startups and small teams, this cost savings is significant. MySQL also offers excellent read performance for web applications with simple query patterns.

The main challenges are converting T-SQL-specific syntax like TOP, IDENTITY, ISNULL, GETDATE(), and stored procedures. This guide covers every difference.

Key Syntax Differences

Feature SQL Server MySQL
Row limitingSELECT TOP 10LIMIT 10
PaginationOFFSET ... FETCH NEXTLIMIT ... OFFSET
Auto-incrementIDENTITY(1,1)AUTO_INCREMENT
Identifier quoting[brackets]`backticks`
String concatenationa + bCONCAT(a, b)
NULL replacementISNULL(a, b)IFNULL(a, b)
Current datetimeGETDATE()NOW()
Boolean typeBITTINYINT(1)
ConditionalIIF(cond, a, b)IF(cond, a, b)
String aggregationSTRING_AGG(col, ',')GROUP_CONCAT(col)

Common Conversions with Examples

TOP to LIMIT

-- SQL Server
SELECT TOP 10 * FROM products ORDER BY price DESC;

SELECT * FROM products
ORDER BY price DESC
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY;
-- MySQL
SELECT * FROM products ORDER BY price DESC LIMIT 10;

SELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20;

IDENTITY to AUTO_INCREMENT

-- SQL Server
CREATE TABLE users (
    id INT IDENTITY(1,1) PRIMARY KEY,
    name NVARCHAR(100) NOT NULL
);
-- MySQL
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
) CHARACTER SET utf8mb4;

Date Function Differences

-- SQL Server
SELECT GETDATE();
SELECT DATEADD(DAY, 30, created_at) FROM orders;
SELECT DATEDIFF(DAY, start_date, end_date) FROM projects;
SELECT FORMAT(created_at, 'yyyy-MM') FROM orders;
-- MySQL
SELECT NOW();
SELECT DATE_ADD(created_at, INTERVAL 30 DAY) FROM orders;
SELECT DATEDIFF(end_date, start_date) FROM projects;
SELECT DATE_FORMAT(created_at, '%Y-%m') FROM orders;

ISNULL to IFNULL

-- SQL Server
SELECT ISNULL(nickname, name) AS display_name FROM users;
SELECT IIF(age >= 18, 'Adult', 'Minor') AS category FROM users;
-- MySQL
SELECT IFNULL(nickname, name) AS display_name FROM users;
SELECT IF(age >= 18, 'Adult', 'Minor') AS category FROM users;

String Concatenation

-- SQL Server (+ operator)
SELECT first_name + ' ' + last_name AS full_name FROM users;
-- MySQL (CONCAT function)
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;

In SQL Server, the + operator returns NULL if any operand is NULL. MySQL's CONCAT also returns NULL if any argument is NULL, but you can use CONCAT_WS (with separator) which skips NULLs.

STRING_AGG to GROUP_CONCAT

-- SQL Server 2017+
SELECT department, STRING_AGG(name, ', ') WITHIN GROUP (ORDER BY name)
FROM employees
GROUP BY department;
-- MySQL
SELECT department, GROUP_CONCAT(name ORDER BY name SEPARATOR ', ')
FROM employees
GROUP BY department;

Data Type Mapping

SQL Server Type MySQL Type Notes
BITTINYINT(1)Boolean
INTINTSame
BIGINTBIGINTSame
FLOATDOUBLE8-byte float
NVARCHAR(n)VARCHAR(n)Use utf8mb4 charset
NVARCHAR(MAX)LONGTEXTUp to 4GB
VARBINARY(MAX)LONGBLOBBinary data
DATETIME2DATETIME(6)Microsecond precision
DATETIMEOFFSETTIMESTAMPMySQL TIMESTAMP stores UTC
MONEYDECIMAL(19,4)No MONEY type in MySQL
UNIQUEIDENTIFIERCHAR(36)Store UUID as string
XMLTEXTNo native XML type in MySQL

Step-by-Step Migration Guide

  1. Export the schema. Use SQL Server Management Studio to script out the database objects. Select all tables, views, and stored procedures.
  2. Convert data types. Replace NVARCHAR with VARCHAR (with utf8mb4), BIT with TINYINT(1), DATETIME2 with DATETIME(6), IDENTITY with AUTO_INCREMENT, and [brackets] with backticks.
  3. Export data. Use BCP (Bulk Copy Program) to export as CSV, then import with MySQL's LOAD DATA INFILE. For smaller databases, generate INSERT statements.
  4. Convert queries. Replace TOP with LIMIT, ISNULL with IFNULL, GETDATE() with NOW(), DATEADD with DATE_ADD, and IIF with IF.
  5. Rewrite stored procedures. T-SQL procedures must be rewritten in MySQL's procedure syntax. Key differences: DECLARE @var becomes DECLARE var, TRY...CATCH becomes DECLARE HANDLER, and BEGIN TRANSACTION becomes START TRANSACTION.
  6. Test and validate. Run your application against MySQL and compare outputs. Pay attention to string collation, date rounding, and NULL behavior differences.

For SQL fundamentals, see our What is SQL guide. For query examples, visit SQL Query Examples.

Convert Automatically with AI2SQL

Stop translating T-SQL syntax manually. Paste your SQL Server query into the SQL Converter tool and get the correct MySQL query with LIMIT, IFNULL, NOW(), and proper data types automatically.

Try the converter free. See also: MySQL to SQL Server. Browse all converter tools.

Frequently Asked Questions

How do I convert SQL Server TOP to MySQL?

Replace SELECT TOP N with LIMIT N at the end of the query. SQL Server: SELECT TOP 10 * FROM users ORDER BY id. MySQL: SELECT * FROM users ORDER BY id LIMIT 10. For OFFSET-FETCH, convert to LIMIT with OFFSET: OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY becomes LIMIT 10 OFFSET 20.

How do I convert SQL Server IDENTITY to MySQL?

Replace IDENTITY(1,1) with AUTO_INCREMENT. SQL Server: id INT IDENTITY(1,1) PRIMARY KEY. MySQL: id INT AUTO_INCREMENT PRIMARY KEY. If the IDENTITY has a non-default seed, set the starting value: ALTER TABLE users AUTO_INCREMENT = 1000.

What happens to NVARCHAR columns when converting to MySQL?

NVARCHAR stores Unicode text in SQL Server. MySQL's VARCHAR with utf8mb4 character set handles the same Unicode data. Replace NVARCHAR(n) with VARCHAR(n) and ensure your MySQL table uses CHARACTER SET utf8mb4. NVARCHAR(MAX) maps to LONGTEXT in MySQL.

Convert SQL Server to MySQL Instantly

Paste your T-SQL query and get correct MySQL syntax generated automatically with our free converter tool.

Convert Now - Free

No credit card required