tags:

views:

577

answers:

4

For example, mysql quote table name using

SELECT * FROM `table_name`;

notice the `

Does other database ever use different char to quote their table name

+1  A: 

The backquotes are not necessary. I don't believe that they are part of the standard for SQL, and I have seen different conventions for when spaces in table names are allowed (e.g. Access uses [])

Lou Franco
+1  A: 

SQL Server uses [square brackets] or "double quotes" when QUOTED_IDENTIFIER option is ON.

I believe double quotes are in the SQL-92 standard.

Alexander Kojevnikov
+8  A: 

This use of quotes is called delimited identifiers. It's an important part of SQL because otherwise you can't use identifiers (e.g. table names and column names) that:

  • Include whitespace: "my table"
  • Include special characters and punctuation: "my-table"
  • Include international characters: "私のテーブル"
  • Are case-sensitive: "MyTable"
  • Match SQL keywords: "table"

The standard SQL language uses double-quotes for delimited identifiers:

SELECT * FROM "my table";

MySQL uses back-quotes by default. MySQL can use standard double-quotes:

SELECT * FROM `my table`;
SET GLOBAL SQL_MODE=ANSI_QUOTES;
SELECT * FROM "my table";

Microsoft SQL Server uses brackets by default. Microsoft can use standard double-quotes:

SELECT * FROM [my table];
SET QUOTED_IDENTIFIER ON;
SELECT * FROM "my table";

InterBase and Firebird need to set the SQL dialect to 3 to support delimited identifiers.

Most other brands of database use double-quotes correctly.

Bill Karwin
I'm trying to format the back-ticks according to the markdown syntax but I can't seem to get it right.
Bill Karwin
Try this:\`ham spam\`
Alexander Kojevnikov
Thanks, that's what I'm doing. It appears correct in the preview but after I save the edit, it reverts to showing the backslashes and putting the word in monospace font. Alas.
Bill Karwin
I have reformatted the answer to put back-quotes into code blocks.
Bill Karwin
+1  A: 

Succinctly, yes.

The SQL standard uses double quotes around the name to indicate a 'delimited identifier'.

Informix by default uses single and double quotes interchangeably to indicate character strings. However, by setting the environment variable DELIMIDENT you can turn on the SQL standard behaviour - single quotes around strings and double quotes around delimited identifiers.

Other people have listed other behaviours for other DBMS; I don't need to repeat those.

Jonathan Leffler