MySQL SQL Server

MySQL to SQL Server Converter: Syntax Guide & Examples

A complete reference for converting MySQL queries to SQL Server (T-SQL). Covers LIMIT to TOP, AUTO_INCREMENT to IDENTITY, quoting, functions, and data types.

Mar 11, 2026 10 min read

Why Convert MySQL to SQL Server?

SQL Server is the standard for enterprise Windows environments and .NET applications. Organizations migrating to Azure often choose SQL Server for tight integration with the Microsoft ecosystem, including Azure SQL Database, Power BI, and SQL Server Reporting Services.

SQL Server also offers features like columnstore indexes for analytics workloads, built-in machine learning services, and temporal tables for tracking data history. If your team is moving to a Microsoft-centric stack, converting MySQL queries to T-SQL is a required step.

The two databases differ significantly in row-limiting syntax, identifier quoting, string functions, and stored procedure language. This guide covers every difference with side-by-side examples.

Key Syntax Differences

Feature MySQL SQL Server
Row limitingLIMIT 10TOP 10 or FETCH NEXT 10 ROWS ONLY
PaginationLIMIT 10 OFFSET 20OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY
Auto-incrementAUTO_INCREMENTIDENTITY(1,1)
Identifier quoting`backticks`[brackets]
String concatenationCONCAT(a, b)CONCAT(a, b) or a + b
NULL replacementIFNULL(a, b)ISNULL(a, b)
Current dateNOW() / CURDATE()GETDATE() / SYSDATETIME()
Boolean typeTINYINT(1)BIT
IF functionIF(cond, a, b)IIF(cond, a, b)
GROUP_CONCATGROUP_CONCAT(col)STRING_AGG(col, ',') (2017+)

Common Conversions with Examples

LIMIT to TOP / FETCH NEXT

-- MySQL
SELECT * FROM products ORDER BY price DESC LIMIT 10;
SELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20;
-- SQL Server (simple limit)
SELECT TOP 10 * FROM products ORDER BY price DESC;

-- SQL Server (with offset / pagination)
SELECT * FROM products
ORDER BY price DESC
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY;

AUTO_INCREMENT to IDENTITY

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

Date Function Differences

-- 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;
-- 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;

Note: SQL Server's DATEDIFF takes the date part as the first argument and the dates in chronological order (start, end), which is the reverse of MySQL's argument order.

IFNULL to ISNULL

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

Boolean Handling

-- MySQL
CREATE TABLE tasks (
    id INT AUTO_INCREMENT PRIMARY KEY,
    done TINYINT(1) DEFAULT 0
);
SELECT * FROM tasks WHERE done = 1;
-- SQL Server
CREATE TABLE tasks (
    id INT IDENTITY(1,1) PRIMARY KEY,
    done BIT DEFAULT 0
);
SELECT * FROM tasks WHERE done = 1;

GROUP_CONCAT to STRING_AGG

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

Data Type Mapping

MySQL Type SQL Server Type Notes
TINYINTTINYINTMySQL: -128 to 127, SQL Server: 0 to 255
TINYINT(1)BITBoolean usage
INTINTSame range
INT UNSIGNEDBIGINTNo UNSIGNED in SQL Server
DOUBLEFLOAT8-byte floating point
VARCHAR(n)NVARCHAR(n)NVARCHAR for Unicode support
TEXTNVARCHAR(MAX)TEXT is deprecated in SQL Server
BLOBVARBINARY(MAX)Binary data
DATETIMEDATETIME2DATETIME2 has better precision
ENUMNVARCHAR + CHECKNo ENUM in SQL Server
JSONNVARCHAR(MAX)SQL Server stores JSON as text
MEDIUMTEXTNVARCHAR(MAX)No size variants in SQL Server

Step-by-Step Migration Guide

  1. Use SQL Server Migration Assistant (SSMA). Microsoft provides a free tool specifically for migrating from MySQL to SQL Server. It handles schema conversion and data transfer automatically.
  2. Convert the schema manually if needed. Replace AUTO_INCREMENT with IDENTITY(1,1), backticks with square brackets, TINYINT(1) with BIT, and VARCHAR with NVARCHAR for Unicode support.
  3. Update queries. Replace LIMIT with TOP or OFFSET-FETCH, IFNULL with ISNULL, NOW() with GETDATE(), GROUP_CONCAT with STRING_AGG, and IF() with IIF().
  4. Convert stored procedures. MySQL stored procedures need to be rewritten in T-SQL. The control flow, variable declaration (DECLARE @var instead of DECLARE var), and error handling (TRY...CATCH instead of HANDLER) are all different.
  5. Test with a staging environment. Run your application test suite against the SQL Server instance and compare results with the MySQL source.

For more on SQL fundamentals, see our What is SQL guide. For query optimization after migration, check 10 Query Optimization Techniques.

Convert Automatically with AI2SQL

Paste your MySQL query into the SQL Converter tool and get correct T-SQL syntax with proper TOP/OFFSET-FETCH, ISNULL, GETDATE(), and all the right data types. No need to remember the differences.

Try the converter free and generate your first SQL Server query in seconds. See also: SQL Server to MySQL. Browse all converter tools.

Frequently Asked Questions

What is the SQL Server equivalent of MySQL LIMIT?

SQL Server uses TOP for simple row limiting: SELECT TOP 10 * FROM table_name. For LIMIT with OFFSET (pagination), use OFFSET-FETCH: SELECT * FROM table_name ORDER BY id OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY. The ORDER BY clause is required when using OFFSET-FETCH.

How do I convert MySQL AUTO_INCREMENT to SQL Server?

Replace AUTO_INCREMENT with IDENTITY(1,1). In MySQL: id INT AUTO_INCREMENT PRIMARY KEY. In SQL Server: id INT IDENTITY(1,1) PRIMARY KEY. The IDENTITY(1,1) means start at 1 and increment by 1. You can change both the seed and increment values.

Does SQL Server support MySQL's backtick quoting?

No. SQL Server uses square brackets [column_name] for identifier quoting instead of MySQL's backticks. SQL Server also supports double quotes if SET QUOTED_IDENTIFIER is ON (which is the default). Best practice is to use square brackets for SQL Server and avoid reserved words as identifiers.

Convert MySQL to SQL Server Instantly

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

Convert Now - Free

No credit card required