Published on

December 16, 2013

Working with SQL Server and MySQL

As a developer, I often find myself working with both SQL Server and MySQL. Each of these database technologies has its own strengths and features that make them valuable in different scenarios. While some people may argue that one is better than the other, I believe that both have their place in the industry.

One challenge I face when working with both SQL Server and MySQL is the difference in statement terminators. In SQL Server, the “GO” keyword is used as a statement terminator, while in MySQL, it is the semicolon (;). This can sometimes lead to issues when copying and pasting SQL scripts between the two platforms.

For example, when I copy a SQL script from SQL Server to MySQL, I may accidentally include the “GO” statement as a terminator. This results in an error (e.g., error 1004) when executing the script in MySQL.

To overcome this issue, I have discovered two workarounds:

  1. Find and Replace: One option is to manually find and replace all instances of the “GO” keyword with a semicolon. However, this can be time-consuming, especially if the script is large. Additionally, the semicolon may end up on a new line, which can make the script look messy and harder to read.
  2. Change the DELIMITER: Another option is to change the delimiter in MySQL for the batch of statements. By temporarily changing the delimiter to “GO,” I can execute the script without modifying the code copied from SQL Server. Once the script is executed, I can change the delimiter back to a semicolon. This approach allows me to seamlessly switch between SQL Server and MySQL without making any code changes.

Here’s an example of how to change the delimiter in MySQL:

DELIMITER GO
SELECT 1
GO
SELECT 2
GO
DELIMITER ;

By using this technique, I can ensure that my SQL scripts work correctly in both SQL Server and MySQL without having to manually modify the code each time.

These workarounds have proven to be effective for my situation, but there may be other tricks or techniques that I am not aware of. If you have any additional tips or suggestions, please let me know!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.