Select a column with a keyword name

前端 未结 6 1018
感动是毒
感动是毒 2020-12-03 15:22

I have a table named \'test\'

It contains a column named \'AND\'

For that I use the following queries

insert into test values (\'a\',\'abc\')         


        
6条回答
  •  抹茶落季
    2020-12-03 15:56

    1. Don't create columns with a name that is a keyword.

    2. If you do create a column with such a name, use backticks (MySQL only) or double quotes (SQL standard) to enclose the name. I'm not certain whether you need to switch on some mechanism to have double quotes work in MySQL. This creates a 'delimited identifier'.

      SELECT `AND` AS a, "AND" AS b
        FROM test;
      

    See also:

    • What does the SQL Standard say about back-quotes
    • SQL standard to escape column names

提交回复
热议问题