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