24

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

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
Azrul Rahim
  • 585
  • 1
  • 5
  • 8

3 Answers3

38

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 SQL_MODE=ANSI_QUOTES;
SELECT * FROM "my table";

Microsoft SQL Server and Sybase uses brackets by default. They can both use standard double-quotes this way:

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
  • 538,548
  • 86
  • 673
  • 828
  • I'm trying to format the back-ticks according to the markdown syntax but I can't seem to get it right. – Bill Karwin Oct 18 '08 at 01:27
  • 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 Oct 18 '08 at 01:34
  • I have reformatted the answer to put back-quotes into code blocks. – Bill Karwin Oct 26 '08 at 23:31
  • 1
    To use backticks within a code block: put in the beginning and the end of the block a double backtick `` and in your code block a single backtick ` – Daan Aug 05 '15 at 23:07
  • In my SQL Server both `[ ]` and `" "` work. Is this also expected? – fedorqui Jun 01 '17 at 08:15
  • 2
    @fedorqui, I would conclude that you or someone else configured `QUOTED_IDENTIFIER=ON` or else that it's now on by default on SQL Server. – Bill Karwin Jun 01 '17 at 16:00
  • Yes! I later on discovered this... and also that you can even name a table `Table]` and then query it with `... FROM [Table]]] ...`. Very weird things. It's very kind of you to enlighten [again](https://stackoverflow.com/a/15005909/1983854), Bill! – fedorqui Jun 01 '17 at 17:56
2

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
  • 17,580
  • 5
  • 49
  • 46
2

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
  • 730,956
  • 141
  • 904
  • 1,278