开发者

SQL Server Query to MySQL query conversion

I am doing query conversion from SQL Server to MySQL. So can anyone suggest a website which provides the different keywords that will do the same operation in SQL Server and MySQL respectively?

For example, To get the current time we will use following keywords

 MSSQL   getdate()
 MYSQL   now()
开发者_开发百科

like this, for all the operations I need keywords.


I did it a few times, my suggestion is to google as following

Mssql getdate() in Mysql

and than you get to sites like http://www.x7media.com/resources/SQL_Differences_Between_Microsoft_SQL_Server_and_MySQL.asp


Have you looked at the MySQL documentation available on the web site?

A quick search found this: A Practical Guide to Migrating From Microsoft SQL Server to MySQL

You have to register to get the document but it's probably worth a read.

I also found this page: Migrating from Microsoft SQL Server and Access to MySQL

Which has some general information on the process and list some migration tools (although some may be specific to Access)


Since the syntax of SQL queries in MS SQLand MySQL are similar but not identical, here are a few tips on converting MS SQL to queries to MySQL:

  1. MySQL does not allow square brackets around table of column names, they all must be replaced by ` symbol or cut off. For instance: [object] will be `object`.

  2. When it comes to JOIN constructions, the keyword WHERE in MS SQL is replaced by ON in MySQL. For example: ... table1 CROSS JOIN table2 WHERE condition must be translated into ... table1 CROSS JOIN table2 ON condition.

  3. When using PHP, most of the SQL functions in MS SQL have the prefix SQLSRV, whereas the functions in MySQL have the prefix MYSQL. For example: sqlsrv_fetch_array, sqlsrv_num_rows ,sqlsrv_query will be converted to mysql_fetch_array, mysql_num_rows, mysql_query.

  4. In MS SQL, the LEN() function is used to return the length of string expression. The MySQL equivalent of this is LENGTH().

  5. CONVERT() function is used to convert an expression of one data type to another in MS SQL. In MySQL, the CONVERT() function converts text data between different character sets. However, there is equivalent function CAST(), so every occurrence of convert(type, expression) in MS SQL query must be replaced by cast(expression AS type) in MySQL query.

Just to list but a few hints. Refer to this page for more. Cheers!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜