Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do different databases use different name quote?

Tags:

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

like image 914
Azrul Rahim Avatar asked Oct 18 '08 01:10

Azrul Rahim


People also ask

Does SQL Use single or double quotes?

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes. That's the primary use anyway.

Are quotes needed in SQL?

SQL requires single quotes around text values (most database systems will also allow double quotes).

What are SQL quotes?

QUOTE() : This function in MySQL is used to return a result that can be used as a properly escaped data value in an SQL statement. The string is returned enclosed by single quotation marks and with each instance of backslash (\), single quote ('), ASCII NULL, and Control+Z preceded by a backslash.

What does double quotes mean in SQL?

Double quotes are used to indicate identifiers within the database, which are objects like tables, column names, and roles. In contrast, single quotes are used to indicate string literals.


1 Answers

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.

like image 140
Bill Karwin Avatar answered Oct 18 '22 07:10

Bill Karwin