gpt4 book ai didi

sql - 在 SQLite 中转义表名?

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:54 25 4
gpt4 key购买 nike

我在 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. Thereare 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] Akeyword enclosed in square brackets is an identifier. This is notstandard SQL. This quoting mechanism is used by MS Access and SQLServer and is included in SQLite for compatibility.

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

来自 SQLite documentation

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com