Monday, 14 April 2014

MySQL error when inserting data containing apostrophes (single quotes)


Apostrophe Delimiter

In the MySQL version of SQL, you signal the beginning and the end of a string with either single quotes or double quotes. Both of the following examples are valid:
  • INSERT INTO COMPANY_TABLE (company_name) VALUES ‘The Fish Shack’;


    INSERT INTO COMPANY_TABLE (company_name) VALUES “The Fish Shack”;

    The following example, however, creates an error:

    INSERT INTO COMPANY_TABLE (tag_line) VALUES ‘Eat at Joe’s -- It’s Good Food!’;

    SQL wants to interpret the string as "‘Eat at Joe’," with everything following the second apostrophe as erroneous. The following text does not fix the problem:

    INSERT INTO COMPANY_TABLE (tag_line) VALUES “Eat at Joe’s -- It’s Good Food!”;

    This would work if the text had only one apostrophe between the double quotes, but this text has two. Also, because some Web-page programming languages use double quotes themselves, you may wish to avoid using them in your SQL.

Web Developer interview question Krawler Information Systems Pvt. Ltd

JAVASCRIPT: Difference between UNDEFINED and NULL Many of times we programmers often get bamboozzled between NULL and UNDEFINED. UNDE...