Solution to conflict between field names and reserved words in Mysql _mysql

Source: Internet
Author: User
Tags reserved

We know that the usual SQL query statements are written in this way:

Copy Code code as follows:
Select Col from table;

That's fine, of course, but what if the field name is "from"?

Copy Code code as follows:
Select from from table;

If this is true, there must be an error, when the field name conflicts with the MySQL reserved word, you can enclose the field name in the character "'":

Copy Code code as follows:
Select ' From ' from table;


Summarize

I just found two fields in the database I originally designed with reserved words (add,comment). An error occurred during insert and update. Remember that SQL Server seems to be surrounded by [] OK. So I tried it and it turned out to be a no-go in MySQL. A simple search on the internet found that the use of brackets. Then came the idea that the SQL statement generated by the MySQL administrator would enclose the table name in single quotes. Try it, or it won't work. But the symbolic discovery of the copy generated can be. Make sure that the symbol is not single quotes. A look is found when the apostrophe (' is the number 1 in front of the key). To solve this problem. Summed up is a sentence:

In MySQL, an apostrophe (') can be used in an SQL statement when a table name or field name or even a database name and a reserved word conflict.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.