MS SQL Server to MySQL

When switching from MS SQL to MySQL, apart from data migration, you must also transfer the application code, which is in the database.
Earlier we discussed how to move MS SQL to a MySQL database using the WorkSQL Workbench tool.
Within the migration, it will only convert tables and copy data, but it will not convert triggers, views, and stored procedures. You must manually convert them to a MySQL database.
To perform this conversion manually, you must understand the basic differences between MS SQL and MySQL queries.
During my conversion from Microsoft SQL Server to a MySQL database, I encountered the following operators and MS SQL queries that were not MySQL compatible, and I had to convert them as shown below.
Creating stored procedures. Syntax
The basic syntax for creating stored procedures is different.
MS SQL Stored, procedure creation syntax:
CREATE PROCEDURE [dbo]. [storedProcedureName]
@someString VarChar(150)
As
BEGIN
-- Sql queries goes here
END
for MySQL procedure creation syntax:
CREATE PROCEDURE storedProcedureName( IN someString VarChar(150) )
BEGIN
-- Sql queries goes here
END
Time table creation
In MS SQL code, I have created several temporary tables that are required to apply. The syntax for creating a temporary table is different, as shown below.
MS SQL syntax for creating a temporary table:
CREATE TABLE #tableName(
emp_id VARCHAR(10)COLLATE Database_Default PRIMARY KEY,
emp_Name VARCHAR(50) COLLATE Database_Default,
emp_Code VARCHAR(30) COLLATE Database_Default,
emp_Department VARCHAR(30) COLLATE Database_Default
)
MySQL syntax for creating a temporary table:
CREATE TEMPORARY TABLE tableName(
emp_id VARCHAR(10),
emp_Name VARCHAR(50),
emp_Code VARCHAR(30),
emp_Department VARCHAR(30)
);
IF syntax
I used many conditions in my stored procedures and triggers that didn’t work after conversion to MySQL because the syntax is different as shown below.
MS SQL condition IF Syntax:
if(@intSomeVal='')
BEGIN
SET @intSomeVal=10
END
MySQL condition IF Syntax:
IF @intSomeVal='' THEN
SET @intSomeVal=10;
END IF;
IF EXIST status
Another common use, if a condition, is to check whether the query returns any lines or not; and if it returns multiple lines, do something. To do this, I used IF EXISTS in MS SQL, which must be converted to MySQL by the IF command as described below.
MS SQL IF EXITS Example:
IF EXISTS(SELECT 1 FROM #tableName WITH(NOLOCK) WHERE ColName='empType' )
BEGIN
-- Sql queries goes here
END
MySQL equivalent is higher, using when the condition is met:
IF(SELECT count(*) FROM tableName WHERE ColName='empType') > 0 THEN
-- Sql queries goes here
END IF;
Date functions
Using data functions within a stored procedure is quite common. The following table shows the differences between MS SQL and MySQL data, related functions.
| MS SQL Server | MySQL Server |
|---|---|
| GETDATE( ) | NOW( ) SYSDATE( ) CURRENT_TIMESTAMP( ) |
| GETDATE( ) + 1 | NOW( ) + INTERVAL 1 DAY CURRENT_TIMESTAMP +INTERVAL 1 DAY |
| DATEADD(dd, -1, GETDATE()) | ADDDATE(NOW(), INTERVAL -1 DAY) |
| CONVERT(VARCHAR(19),GETDATE()) | DATE_FORMAT(NOW(),’%b %d %Y %h:%i %p’) |
| CONVERT(VARCHAR(10),GETDATE(),110) | DATE_FORMAT(NOW(),’%m-%d-%Y’) |
| CONVERT(VARCHAR(24),GETDATE(),113) | DATE_FORMAT(NOW(),’%d %b %Y %T:%f’) |
| CONVERT(VARCHAR(11),GETDATE(),6) | DATE_FORMAT(NOW(),’%d %b %y’) |
Announcement of variables
In MS SQL stored procedures, you can declare variables somewhere between “Begin” and “end”.
However, in MySql, you will have to declare them only after you declare the stored “begin” procedure. A declaration of a variable at any point between is not allowed.
Select the first N records
In MS SQL, you will use SELECT, TOP if you want to select only the first few records. For example, to select the 1st 10 records, you will do the following:
SELECT TOP 10 * FROM TABLE;
In MySQL, you will have to use LIMIT instead of TOP as shown below.
SELECT * FROM TABLE LIMIT 10;
Converting an integer number to Char
In MS SQL you will perform the following steps (Convert functions) to convert an integer to a character.
CONVERT(VARCHAR(50), someIntVal)
In MySQL, you will use the CAST function to convert an integer to a character, as shown below.
CAST( someIntVal as CHAR)
Concatenation operator
If you manipulate a lot of data inside a stored procedure, you can use some string concatenation execution.
In MS SQL the concatenation operator + character. An example of such usage is shown below.
SET @someString = '%|' + @someStringVal + '|%'
In MySQL, if you use the AnSi mode, it is the same as in MS SQL. i.e. + character will work for concatenation.
But, in the default MySQL mode, we have to use the CONCAT function (“str1”, “str2”, “str3″… “strN”).
SET someString = CONCAT('%|', someStringVal, '|%');
Enteros
About Enteros
IT organizations routinely spend days and weeks troubleshooting production database performance issues across multitudes of critical business systems. Fast and reliable resolution of database performance problems by Enteros enables businesses to generate and save millions of direct revenue, minimize waste of employees’ productivity, reduce the number of licenses, servers, and cloud resources and maximize the productivity of the application, database, and IT operations teams.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
How to Optimize Aerospace and Defense Operations with Enteros Database Software, Database Observability, and AI-Powered Analytics
- 26 July 2026
- Database Performance Management
Introduction The aerospace and defense (A&D) industry operates some of the world’s most sophisticated and mission-critical technology environments. Aircraft manufacturers, defense contractors, space organizations, satellite operators, maintenance providers, and government defense agencies manage enormous volumes of engineering, manufacturing, logistics, operational, and security data every day. From aircraft design and production to fleet maintenance, mission planning, … Continue reading “How to Optimize Aerospace and Defense Operations with Enteros Database Software, Database Observability, and AI-Powered Analytics”
How to Optimize Automotive Manufacturing with Enteros Database Software, AI-Powered Analytics, and Operational Intelligence
Introduction The automotive industry is undergoing its most significant transformation in decades. Traditional vehicle manufacturing is rapidly evolving with electric vehicles (EVs), autonomous driving technologies, connected cars, smart factories, robotics, Industrial Internet of Things (IIoT), artificial intelligence (AI), and cloud computing. Automotive manufacturers and suppliers must manage increasingly complex operations while maintaining production efficiency, product … Continue reading “How to Optimize Automotive Manufacturing with Enteros Database Software, AI-Powered Analytics, and Operational Intelligence”
How AI-Powered Database Observability Strengthens Enterprise Cyber Resilience
Introduction Cyberattacks have evolved dramatically over the past decade. Modern enterprises face increasingly sophisticated ransomware attacks, insider threats, supply chain compromises, credential theft, and advanced persistent threats (APTs). As organizations continue adopting cloud-native architectures, hybrid environments, and distributed applications, protecting enterprise databases has become one of the highest cybersecurity priorities. Databases store an organization’s most … Continue reading “How AI-Powered Database Observability Strengthens Enterprise Cyber Resilience”
How Database Observability and AIOps Work Together to Improve Business Continuity
- 24 July 2026
- Software Engineering
Introduction In today’s digital-first economy, business continuity depends heavily on the availability, reliability, and performance of enterprise applications. Organizations across banking, financial services, healthcare, education, retail, telecommunications, SaaS, and e-commerce rely on complex technology ecosystems where databases serve as the foundation for critical operations. Every customer transaction, online service request, healthcare record update, financial operation, … Continue reading “How Database Observability and AIOps Work Together to Improve Business Continuity”