何时在 SQL 语句中使用单引号? [英] When to use single quotes in an SQL statement?
问题描述
我知道在处理 TEXT 类型的数据时应该使用它(我猜是那些回退到 TEXT 的数据),但这是唯一的情况吗?
I know that I should use it when I deal with data of TEXT type (and I guess the ones that fall back to TEXT), but is it the only case?
示例:
UPDATE names SET name='Mike' WHERE id=3
我正在用 C++ 编写 SQL 查询自动生成,所以我想确保在我必须添加引号时不会遗漏案例.
I'm writing an SQL query auto generation in C++, so I want to make sure I don't miss cases, when I have to add quotes.
推荐答案
单引号 ('
) 表示文本数据,正如您所指出的(例如,'Mike'
in你的例子).数字数据(例如,您示例中的 3
)、对象(表、列等)名称和句法元素(例如,update
、set
, where
) 不应包含在引号中.
Single quotes ('
) denote textual data, as you noted (e.g., 'Mike'
in your example). Numeric data (e.g., 3
in your example), object (table, column, etc) names and syntactic elements (e.g., update
, set
, where
) should not be wrapped in quotes.
这篇关于何时在 SQL 语句中使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!