10 tips on converting MS SQL queries to MySQL

  • Hugo Kornelis (6/1/2012)


    Jonathan AC Roberts (6/1/2012)


    Hugo Kornelis (6/1/2012)


    Jonathan AC Roberts (6/1/2012)


    I didn't realise that, I thought it was open source and anyone could use it.

    Where does it say that you can't use it for that purpose?

    Here: http://www.mysql.com/about/legal/licensing/index.html

    (I googled for "mysql license"; this was the first hit)

    What bit of the license says you can't use the GPL License for a database that sits behind a commercial web site?

    The first part says when you can use MySQL for free: if you are developing and distributing open source projects, either under the GPL license or uner an OSI-approved license. If you are developing open source software, this applies and you can use MySQL for free, under the GPL license, possibly with a FLOSS exception.

    The second part is for parties who wish to redistribute MySQL. That doesn;t apply here.

    The third part is for web sites, enterprise IT and government IT; this probably applies to you. In these cases, MySQL Enterprise is required. The link takes me to a page full of options (that I didn;t all explore, since I'm currently working through a slow internet connection over my phone), and a "buy now" link that takes me to another page, quoting prizes ranging from from $2,000 to $30,000 ... per year.

    If none of the three points applies, than the page I linked to doesn't give any information. Since this would mostly include private use and small-to-medium sized (non enterprise) companies hosting their own database, I assume the license is free in this case - but it would be nice if the information given wa a bit more conclusive.

    All that being said - I also found some information that doesn't support the above interpretation. Even though it doesn't say so, it seems that the page I first found only applies to DISTRIBUTING MySQL (or parts of it - such as libraries to connect to MySQL). See for instance http://www.xaprb.com/blog/2009/02/17/when-are-you-required-to-have-a-commercial-mysql-license/[/url] and http://stackoverflow.com/questions/225987/can-someone-explain-mysqls-license-and-what-it-means-to-closed-source-developme.

    Lessons learned:

    1. I should have investigated further instead of only following the first link and posting it; and

    2. It's hard to find good information on MySQL licensing; if you ever get involved in decisions on this area, make sure to do a thorouh investigation first.

    There is a good reason why Oracle don't make it clear that the use of the GPL license is free. They want to sell a support contract.

  • this paper is unworthy of sqlservercentral.

    Some mention are totally false...

    Example :

    1) "Microsoft SQL provides effective solution to avoid naming objects conflict and to manage user permissions on data access. This is schema,..."

    SQL Schema is a plain part of SQL ISO/ANSI standard since 1992 (SQL 2) and has nothing to do with user permissions, despite the fact that since SQL Server version 2005, security can be granted at the database or schema level. MySQL has no SQL Schema and it is not possible to convert directly MS SQL Server databases with different SQL Schemas in a MySQL server.

    2) "CONVERT() function is used to convert an expression of one data type to another in Microsoft SQL. In MySQL CONVERT() function converts text data between different character sets. However, there is equivalent function CAST()..."

    CAST is the SQL ISO/ANSI standard and works both on MySQL and MS SQL Server. However, CONVERT has a third parameter that had patterns functionnality to the conversion of datatypes, most of them are for date and time datatypes.

    3) 4) "MS SQL function CONTAINS(expression, template) searches for matches of template inside expression. MySQL has operator LIKE that implements the same semantics: expression LIKE %template% "

    CONTAINS is an ISO/ANSI SQL Standard Full text function and had absolutly noting to do with LIKE operator that MS SQL Server have also.

    CONTAINS can be used to find :

    a simple word : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' "word" ')

    a composite word : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' "daughter-in-law" ')

    a word begining by : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' "begin*" ')

    differents logical combination of words : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' "war" AND "peace" OR "love" ')

    some synonyme : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' FORMSOF ( THESAURUS, "engine" ) ')

    inflectional words : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' FORMSOF ( INFLECTIONAL, "mystery" ) ')

    proximity : CONTAINS ( ( my_list_of_full_text_indexed_columns), ' "war" NEAR "peace" ')

    and so on.... (many other predicates can be use to make fuzzy search, weigthed search...)

    Quite a difference with the simple LIKE and quite a difference with the ugly full text search solution of MySQL !

    some other mention are almost incomplete...

    4) "MS SQL operator '+' allows to concatenate strings like this: 'string1' + 'string2'. In MySQL such expressions must be replaced by CONCAT('string1', 'string2'). "

    Due to the lack of SQL ISO/ANSI Standard datatype in MySQL, concatenations of strings does not works properly in MySQL and transposition of + in CONCAT can bring and incorrct result in MySQL.

    Demo...

    MS SQL Server (wich respects the standard SQL) :

    CREATE TABLE T_TEST

    (DATA1 VARCHAR(8),

    DATA2 CHAR(8),

    DATA3 CHAR(8));

    INSERT INTO T_TEST VALUES ('aaa', 'aaa', 'aaa');

    SELECT DATA1 + DATA3 + DATA2 + '*' AS CONCATENATION

    FROM T_TEST

    CONCATENATION

    -------------------------

    aaaaaa aaa *

    MySQL wrong usage of CONCAT... :

    CREATE TABLE T_TEST

    (DATA1 VARCHAR(8),

    DATA2 CHAR(8),

    DATA3 CHAR(8));

    INSERT INTO T_TEST VALUES ('aaa', 'aaa', 'aaa');

    SELECT CONCAT(DATA1, DATA3, DATA2, '*') AS CONCATENATION

    FROM T_TEST;

    CONCATENATION

    --------------

    aaaaaaaaa*

    5) "Syntax of JOIN constructions are very similar in MS SQL and MySQL."

    NO ! MySQL use the ugly NATURAL JOIN that MS SQL rejected because of many confusion possible (in this cas join is based on column name equality...).

    And CROSS JOIN cannot have an ON clause in SQL ISO/ANSI standard because in this case the operator is not a "cross product" ! So the ON clause added to the CROSS JOIN is one of the multiple stupidities of MySQL !

    I stopped there the massacre...

  • Here is too much emotions for IT professional instead of logic and facts, ins't? 😉

  • Hugo Kornelis (6/1/2012)


    ...

    1) Sometime MS SQL table or column names are enclosed in square brackets in queries (e.g. if contains spaces or for some other reasons). MySQL does not allow square brackets around table of column names, they all must be replaced by ` symbol or cut off: [object] -> `object`.

    The square brackets used by SQL Server are a hideous deviation from the ANSI standard. And there is no reason why everyone keeps using them, as the ANSI standard delimiter, double quotes, is supported by SQL Server as well. So unless you are really sure that you'll never port to other databases, avoid the [square brackets] and uses "quotation marks" instead. (Or, better yet, stick to identifier names that don't need delimiters).

    ...

    While I agree with almost everything you said, Hugo, I think it only fair to point out that the phrases "square brackets" and "double quotes" are themselves "hideous deviations" from standard English. And all the more so, since they already have perfectly acceptable names. "Square brackets" are really just "brackets", there being no other kind. Though the illiterati of the Unix/C legacy that created these terms qualified it so to distinguish them from the non-existent "curly brackets", which are actually known as "braces" in the English-speaking world. As both of the English terms are shorter, yet still as explicit, there was no need to create them, even under the rules of jargon where they try to hide.

    The term "double quotes" suffers from the same problems (and from the same source), because they are properly called "quotation marks", though again, the Unix-world needlessly invented the term to distinguish them from the equally non-existent "single quotes". Those are normally called "apostrophes" which all programmers seem to forget, until the first time they realize that the already present apostrophes in their user/file input is actually the same as the "single quotes" that they are trying to use to quote the strings they are sending to another facility. Something that might have occurred to us beforehand, if we didn't keep referring to them as though they were something different. And this reference to a double/single "quote" is all the more hideous because "quote" is actually a verb, not a noun.

    And yes, I recognize that this is a lost cause (and a wee bit rude, sorry), and would not normally bother to point it out any of the hundreds of times a day that I have to read it, but since we were talking about hideous deviations from standard language, I did think that it was fair to point out just how indoctrinated to such deviations we have all become.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Jonathan AC Roberts (6/1/2012)


    IceDread (6/1/2012)


    Jonathan AC Roberts (6/1/2012)


    IceDread (6/1/2012)


    I see no valid reason to why you'd want to do this.

    If you want to go from MS Sql server, you certainly do not want to go to Oracle MySql.

    The reason is that MySQL is free, SQL Server has massive licensing costs.

    Because it's free does not make it good. There are better free options available.

    I'm not an expert in open-source/free databases and which ones are better or worse. Can you provide a list of ones that are better and why they are better?

    PostgreSQL 😉

    I'd hate to be in oracles claws.

  • There are an error on the TIP 10. the WHERE clause is not allowed on JOINS on MS-SQL Server.

  • dayanjor (6/8/2012)


    There are an error on the TIP 10. the WHERE clause is not allowed on JOINS on MS-SQL Server.

    Who told you that?!

  • This is a technical article, so regardless of the reasons, I'm glad people are starting to post about it.

    I have a lot of love for SQL Server. However, there are valid reasons for wanting to convert to MySQL from SQL Server:

    1)Costs! Microsoft's pricing policies have become very aggressive. This is becoming a significant driver today.

    a) I know what you're thinking, MySQL is a paid-for db now as well if used commercially. But not MariaDB, which is an open source drop in replacement for MySQL. I highly recommend giving MariaDB a look. They really have their act together.

    2)Platform freedom. MS Sql Server still locks you into windows. MySQL and MariaDB open up the doors to Linux distributions.

Viewing 8 posts - 31 through 37 (of 37 total)

You must be logged in to reply to this topic. Login to reply