Wednesday, July 4, 2012

ten Recommendations on Converting MS SQL Queries to windows 7 key

When migrating databases from Microsoft SQL to MySQL server it is actually normally necessary to translate SQL queries according to MySQL syntax as well. Syntax of SQL queries in MS SQL and MySQL are similar but not identical. This article discovers ten most well-known differences between MS SQL and MySQL syntax. The target audience for this guide should have common database management expertise and experience in composing SQL windows 7 anytime upgrade home premium to professional queries.

1) Sometime Microsoft SQL table or column names are enclosed in square brackets in queries (e.g. if consists of spaces or for some other motives). MySQL will not enable square brackets about table of column names, they all has to be replaced by ` symbol or cut off: [object] -> `object`.

2) MS SQL provides effective solution to avoid naming objects conflict and to manage user permissions on data access. This is schema, a logic container used to group  and categorize objects inside the single database. When using schema the full name of database object in query may look like %database%.%schema%.%object%. However, there is no such semantic in MySQL, so all schema names should be cut off from queries.

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

4) LEN() function returns length of string expression in MS SQL. MySQL equivalent for this function is LENGTH().

5) MS SQL function DATEADD() adds interval to the specified part of the date. MySQL operator '+' can do exactly the same as follows:
DATEADD(year, 1, %expression%) -> %expression% + interval 1 year
DATEADD(month, 1, %expression%) -> %expression% + interval 1 month
DATEADD(day, 1, %expression%) -> %expression% + interval 1 day
6) GETDATE() function returns the current system date and time in MS SQL. MySQL equivalent for this function is NOW().
7) MS SQL operator '+' allows to concatenate strings like this: 'string1' + 'string2'. In MySQL such expressions should be replaced by CONCAT('string1', 'string2').
8) Microsoft SQL function Contains(expression, template) searches for matches of template inside expression. MySQL has operator LIKE that implements exactly the same semantics: expression LIKE %template%
9) If Microsoft SQL query consists of 'TOP (100) PERCENT' pattern just cut it off when composing MySQL query. If there is another percentage amount in that pattern, it may be replace by the following code in MySQL (works in MySQL 5.0.7 and higher):
SET @amount =(SELECT COUNT(*) FROM %table name%) * %percentage% / ten;
PREPARE STMT FROM '%original query% FROM %table name% LIMIT?';
EXECUTE STMT USING @amount;
10) Syntax of JOIN constructions are very comparable in both database systems. The only difference is that MS SQL keyword 'WHERE' is replaced by 'ON' windows 7 enterprise activation in MySQL. For example:
'... %table1% cross join %table2% where %condition%'
must be translated into
'... %table1% cross join %table2% on %condition%'

Source: http://www.windowskeyshop.com/

No comments:

Post a Comment