sql - 在 SQLite 中转义表名?

标签 sql database sqlite escaping

我在 SQLite 中有一个名为 References 的表,所以我似乎无法定位它。我用来编辑数据库的 SQLite Studio 抛出错误。

有没有办法转义数据库名称?

查询是:

UPDATE References 
SET DateTimeLastEdited = datetime('now', 'localtime')
WHERE NewsItemID = old.NewsItemID;

(这是我正在制作的触发器的一部分。)

最佳答案

您可以使用双引号对表名进行转义:

UPDATE "References" SET DateTimeLastEdited = datetime('now', 'localtime') WHERE NewsItemID = old.NewsItemID;

根据要转义的内容,需要使用不同的分隔符:

If you want to use a keyword as a name, you need to quote it. There are four ways of quoting keywords in SQLite:

'keyword' A keyword in single quotes is a string literal.

"keyword" A keyword in double-quotes is an identifier.

[keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.

`keyword` A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.

来自 SQLite documentation

关于sql - 在 SQLite 中转义表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34884362/

相关文章:

java - 如何将秒表 JavaScript 中的数据存储到 MySQL

android - 如何在多列sqlite数据库上过滤多个数据

wpf - 使用 SQLite 和 Entity Framework 进行数据绑定(bind)

sql - 简单的选择会占用大量时间

mysql - 无需临时表的快速 SQL 搜索和排序

SQL 下一个最近的记录

Android SQLite 数据库 database/data/data/... (conn# 0) 已经关闭

database - 如何捕捉到不存在的 Rose::DB 数据库的连接失败?

java - 在java中设置数据库文件的路径

PHP/SQL 将 sql 结果分配给 session