Home > Database > Mysql Tutorial > How Do I Escape Column Names in MySQL, SQLite, and SQL Server?

How Do I Escape Column Names in MySQL, SQLite, and SQL Server?

Mary-Kate Olsen
Release: 2025-01-11 22:02:47
Original
938 people have browsed it

How Do I Escape Column Names in MySQL, SQLite, and SQL Server?

Escape column names in SQL database

Does SQL have a standardized way to escape column names? If not, what methods are supported by MySQL, SQLite and SQL Server?

SQL standards and identifier delimiters

The SQL:1999 standard states that identifiers, including column names, must be enclosed in double quotes (") as delimiters.

<code><delimited identifier=""> ::= <double quote=""><delimited body="" identifier=""><double quote=""></double></delimited></double></delimited></code>
Copy after login

Support for delimited column names

Most popular SQL databases, including Oracle, PostgreSQL, MySQL, MSSQL, and SQLite, support the use of double quotes as identifier delimiters. However, not all databases use this as the default setting.

MySQL

In MySQL, to use double quotes as column name delimiters, ANSI mode must be enabled.

SQL Server

In SQL Server, double quotes are supported as column name delimiters only when the QUOTED_IDENTIFIER option is set to ON.

Example usage

To use double quotes to escape column names in these databases, simply surround the column name with quotes.

<code>SELECT * FROM "table_name" WHERE "column_name" = 'value';</code>
Copy after login

Note:

Although double quotes are the standard way to escape column names, some databases may also support other delimiters, such as square brackets ([ and ]). However, it is generally recommended to use double quotes to ensure compatibility and consistency across different databases.

The above is the detailed content of How Do I Escape Column Names in MySQL, SQLite, and SQL Server?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template