The role of anti-quote when MySQL creates a table

Source: Internet
Author: User

When you try the Navicat tool to view the current MySQL build table statement, it is found that the table name and field names are quoted in reverse quotation marks.

CREATE TABLE ' Tab_notice_title_tv ' (  ' i_id ' int (one) not NULL auto_increment,  ' c_opcom_key ' varchar (+) DEFAULT NULL,  ' c_view_type ' int (one) default ' 1 ' COMMENT ' platform type, 1: SD, 2: HD ',  ' c_title ' varchar (+) default NULL,  ' c_ Status ' int (2) Default ' 0 ',  ' c_creator ' varchar (+) Default ',  ' c_createtime ' varchar (+) default NULL,  ' C _deleted ' int (2) not NULL default ' 0 ',  PRIMARY KEY (' i_id ')) Engine=myisam auto_increment=46 default CHARSET=GBK;

Anti-quotes, usually below the ESC key.
It is a symbol that is introduced to differentiate between MySQL's reserved words and ordinary characters.
For example: Select ' Select ' From ' Test ' WHERE select= ' field value '
In the test table, there is a select field, without the use of anti-quotes, MySQL will treat select as a reserved word resulting in an error, so there is a MySQL reserved word as a field, you must add the anti-quote to distinguish.
Quotation marks are generally used in the value of the field, and if the field value is a character or string, enclose it in quotation marks, such as: select= ' field value '
Tables built without anti-quotes cannot contain mysql reserved words, otherwise an error occurs

The name of the anti-quote, this is actually to prevent when the field is a keyword, with this symbol can not be an error

CREATE TABLE ' zz_files ' (  ' id ' int (one) unsigned not null auto_increment,  ' data_id ' int (one) ' DEFAULT NULL,  ' Nam E ' varchar (COLLATE) utf8_unicode_ci default null,  ' fileurl ' varchar (+) COLLATE utf8_unicode_ci default NULL,  ' ext ' varchar COLLATE utf8_unicode_ci DEFAULT NULL COMMENT ' extension ',  ' cate ' varchar (in) COLLATE Utf8_unicode_ CI default null,  ' desc ' int (one) default null,  ' c_time ' int (one) default null,  PRIMARY KEY (' id ')) engine=myisa M auto_increment=12 DEFAULT Charset=utf8 collate=utf8_unicode_ci

As with the DESC keyword, this symbol will not go wrong.

Reference links

Http://blog.163.com/[email protected]/blog/static/66693350201721651918235/

(ext.) The effect of anti-quotation marks when MySQL creates a table

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.