10 tips on converting MS SQL queries to MySQL

  • You could get a multiprocessor SQL Server machine with a $1000 a month per cpu license fee or you could find an open source database that would do the necessary job for free.

    ermmm... i'm not sure where you're getting you're license costs from , but i think your vendor is ripping you off if your're paying $1000 per month per cpu

    if you can limit the number of CALs required - since it's competing with mysql then sql standard edition is more than adequate - you can get it for less than £700 (for a permanent license), or even a cpu license is cheaper than $12000 per year per CPU

    MVDBA

  • You may not need to specifically convert from one to another, but it is very helpful to know the differences. I have someone I supervise who uses a MySQL db exclusively, where my experience is primarily in MS SQL. So having a list of the differences between the two languages will be very helpful when I'm trying to assist him in debugging a query, for example.

  • joking aside - if any company wants to run enterprise scale applications on open source or free software then i'd start looking for another company. They sure as hell aren't going to invest in you if they don't invest in their tools.

    if it's not an enterprise scale application then really mysql is proboably as good a choice as any (you have oracle express, sql express, MongoDB)

    but your comments about cpu limitations etc lead me to indicate that your company might be trying to to do something big with innapropriate tools ???

    MySQL is quite appropriate when used for a website, for example. There are limitations on the number of users that can access the free version of MS SQL, as we all know, that MySQL does not have. If you are a small to medium company with a need for a db on your website or for an application then MySQL is a perfectly legitimate, effective solution. Yes, a large company with 10's of thousands of employees will not be using MySQL for enterprise data warehousing, for example. But there are plenty of uses that fall in between the two extremes, and MySQL is a very cost-effective alternative to MS SQL.

    And I am an MS SQL person, btw, NOT a MySQL person. But let's be real here.

  • michael vessey (6/1/2012)


    You could get a multiprocessor SQL Server machine with a $1000 a month per cpu license fee or you could find an open source database that would do the necessary job for free.

    ermmm... i'm not sure where you're getting you're license costs from , but i think your vendor is ripping you off if your're paying $1000 per month per cpu

    if you can limit the number of CALs required - since it's competing with mysql then sql standard edition is more than adequate - you can get it for less than £700 (for a permanent license), or even a cpu license is cheaper than $12000 per year per CPU

    If you are supplying SQL Server have multiple vendors and using SPLA licenses the cost is not far off $1,000 per cpu per month for enterprise edition, possibly half that for standard edition and that's paying Microsoft directly, no third party vendor.

  • Having worked extensively with both databases, I know first-hand how much more capable MS SQL Server is than MySQL. Things we take for granted in SQL Server are just not possible in MySQL, it is hair-pullingly (is that a word?) frustrating. For instance, in a troubleshooting script, you cannot declare variables. You can only declare variables inside a stored procedure or function. You cannot build a concatenated variable in a select statement (select @variable = @variable + x from dbo.table). Among others.

    I know I would not enjoy a project of converting code from MS SQL to MySQL. I wish you all the best if you are assigned such a task.

    Hakim Ali
    www.sqlzen.com

  • If you are supplying SQL Server have multiple vendors and using SPLA licenses the cost is not far off $1,000 per cpu per month for enterprise edition, possibly half that for standard edition and that's paying Microsoft directly, no third party vendor.

    and you just made my point exactly

    why would you use enterprise edition for a simple read only database? it's not a direct comparison.

    i'm not sure i understand your "multiple vendors" issue (or do you mean multiple customers ?) - but every time we've paid licenses (PER CPU) they are a one off hit not a monthly rental. the only difference between cost of MSSQL server and a MYSQL server (where the hardware and OS are equivalent) is the cost of the SQL license. - try looking at web edition and workgroup edition to shave even more off your costs.

    MVDBA

  • michael vessey (6/1/2012)


    If you are supplying SQL Server have multiple vendors and using SPLA licenses the cost is not far off $1,000 per cpu per month for enterprise edition, possibly half that for standard edition and that's paying Microsoft directly, no third party vendor.

    and you just made my point exactly

    why would you use enterprise edition for a simple read only database? it's not a direct comparison.

    i'm not sure i understand your "multiple vendors" issue (or do you mean multiple customers ?) - but every time we've paid licenses (PER CPU) they are a one off hit not a monthly rental. the only difference between cost of MSSQL server and a MYSQL server (where the hardware and OS are equivalent) is the cost of the SQL license. - try looking at web edition and workgroup edition to shave even more off your costs.

    multiple vendors meant "multiple customers". If you have multiple customers you need a SPLA license which is per cpu per month.

  • Jonathan AC Roberts (6/1/2012)


    michael vessey (6/1/2012)


    If you are supplying SQL Server have multiple vendors and using SPLA licenses the cost is not far off $1,000 per cpu per month for enterprise edition, possibly half that for standard edition and that's paying Microsoft directly, no third party vendor.

    and you just made my point exactly

    why would you use enterprise edition for a simple read only database? it's not a direct comparison.

    i'm not sure i understand your "multiple vendors" issue (or do you mean multiple customers ?) - but every time we've paid licenses (PER CPU) they are a one off hit not a monthly rental. the only difference between cost of MSSQL server and a MYSQL server (where the hardware and OS are equivalent) is the cost of the SQL license. - try looking at web edition and workgroup edition to shave even more off your costs.

    multiple vendors meant "multiple customers". If you have multiple customers you need a SPLA license which is per cpu per month.

    and the SPLA licence only appliers to Providers - which a very specific scenario

    you do realise then that you can't use the community edition for that purpose and you still need to pay for the commercial license for MYSQL - else you are in breach of the GPL licensing agreement

    http://www.mysql.com/products/

    MVDBA

  • michael vessey (6/1/2012)


    Jonathan AC Roberts (6/1/2012)


    michael vessey (6/1/2012)


    If you are supplying SQL Server have multiple vendors and using SPLA licenses the cost is not far off $1,000 per cpu per month for enterprise edition, possibly half that for standard edition and that's paying Microsoft directly, no third party vendor.

    and you just made my point exactly

    why would you use enterprise edition for a simple read only database? it's not a direct comparison.

    i'm not sure i understand your "multiple vendors" issue (or do you mean multiple customers ?) - but every time we've paid licenses (PER CPU) they are a one off hit not a monthly rental. the only difference between cost of MSSQL server and a MYSQL server (where the hardware and OS are equivalent) is the cost of the SQL license. - try looking at web edition and workgroup edition to shave even more off your costs.

    multiple vendors meant "multiple customers". If you have multiple customers you need a SPLA license which is per cpu per month.

    and the SPLA licence only appliers to Providers - which a very specific scenario

    you do realise then that you can't use the community edition for that purpose and you still need to pay for the commercial license for MYSQL - else you are in breach of the GPL licensing agreement

    http://www.mysql.com/products/

    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?

  • 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)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (6/1/2012)


    I don't really like this article, as a lot of the tips are lacking background information or giving less than optimal advise.

    [..]

    9) [If MS SQL query contains 'TOP (100) PERCENT' pattern] ...

    The first part of that sentence can be shortened to "If MS SQL query contains 'TOP (100) PERCENT' pattern just cut it off". It's just a waste of bytes.

    The replacement pattern looks quite inefficient to me (as the query has to be executed twice), but since I never used MySQL, I can't verify it. I'd also be concerned about the risk of SQL injection, since it uses dynamic SQL.

    I'd agree with the first part of this, but (ahem) I have to correct the second snippet I've quoted above. Not Hugo's fault, because the author isn't giving the correct replacement, IMO.

    In MySQL you should use the LIMIT <bottom>, <top> clause that MS SQL doesn't have. Sure, LIMIT is numeric only, doesn't have the percentage option. But it's far more flexible -- if anybody cares, it works in update and delete too -- and it's trivial to figure out the numeric values based on the percentage you want, without dynamic sql.

    I am not sure why the author didn't propose LIMIT unless it only works in some more recent versions of MySQL than he wanted to cover (or he doesn't know about it, which is far more likely). I bet how to get equivalent functionality to LIMIT from MS SQL is an FAQ item on MySQL developer sites!

    More generally (not replying to only Hugo here): IMHO here are two reasons why it doesn't hurt all of us to be aware of appropriate techniques in different db environments:

    1 - volunteer work.

    We're all MS SQL professionals. But, to our friends and relations and other non-work associates, we're "database professionals", full-stop. This sometimes means we get roped into support on volunteer projects built on an open-source stack, often without ability to have input on technology at the beginning of the project.

    In my case, that would be my university class website, which is built in joomla on MySQL. They wanted some customization and integration with the main alumni association data, which turned out to require a fair amount of ETL, sprocs, etc.

    I can't say I've grown to love doing this. But I'm not going to say "no" to my classmates just because I turn up my nose at the techology they chose, or at the concomitant work and energy they've put into the non-database parts of this site.

    And I can't believe nobody else here does any volunteer work that has a database component?

    2 - embedded/appliance integration work.

    Our employers and our clients are generally on the MS stack, true. But occasionally they may buy self-contained appliances with embedded databases. I'm going to bet a best-of-breed appliance is *not* running Windows (maybe someday with WinRT, maybe not, and who knows whether even if it is, who knows if it will support SQL Express).

    You can get more value out of the appliance if you can figure out to do some integration -- and you'll do better integration if you know a little bit more about the embedded database. It's a good idea to stay open to this possibility.

    FWIW I have a little experience with this, but I wouldn't have thought about it except that my husband -- who happens to be an Oracle guy -- is going through exactly this scenario right now <g>.

    It doesn't really matter who "owns" MySQL. IMO, from an Oracle POV, MySQL is just as foreign as it is to us, except for one difference, which might be critical for some scenarios:

    Oracle has some degree of platform independence. Neither SQL Express, SQL Compact, nor SQL LocalDB will run anyplace but Windows AFAIK. (Please somebody tell me otherwise if you know otherwise.)

    >L<

  • 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?

  • 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?

    No part. You have to use the commercial license if you are distributing MySql with your products and don't distribute your source under GPL. That's all, and it doesn't apply to a commercial web site unless that web site is distributing its source.

    You can also *choose* to use the commercial license if you want some extra goodies. See http://www.mysql.com/products/ and look for items annotated with (1) - "1 Features only available in Commercial Editions."

    >L<

  • Lisa Slater Nicholls (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?

    No part. You have to use the commercial license if you are distributing MySql with your products and don't distribute your source under GPL. That's all, and it doesn't apply to a commercial web site unless that web site is distributing its source.

    You can also *choose* to use the commercial license if you want some extra goodies. See http://www.mysql.com/products/ and look for items annotated with (1) - "1 Features only available in Commercial Editions."

    >L<

    Thanks, that's what I thought. I'm not sure what Hugo mean't as most uses of SQL Server are for hosting applications.

  • 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.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

Viewing 15 posts - 16 through 30 (of 37 total)

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