理解SQL/DDL查询中关于case的一句话

发布于 2024-07-29 05:16:29 字数 350 浏览 2 评论 0原文

这个问题基于这个答案

下面这句话是什么意思?

最后,不要使用混合大小写 身份标识。 一切都小写, 所以你不必引用它们。

这是否意味着我应该将 CREATE TABLE、USER_ID 和 NOT NULL 等命令更改为小写? - 不能,因为这违反了常见的命名约定。

This question is based on this answer.

What does the following sentence mean?

Finally, don't use mixed case
identifiers. Do everything lowercase,
so you don't have to quote them.

Does it mean that I should change the commands such as CREATE TABLE, USER_ID and NOT NULL to lowercase? - It cannot because it would be against common naming conventions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏月而来 2024-08-05 05:16:29

PostgreSQL 中,不带引号的标识符会转换为小写:

CREATE TABLE "MYTABLE" (id INT NOT NULL);

CREATE TABLE "mytable" (id INT NOT NULL);

INSERT
INTO    "MYTABLE"
VALUES  (1);

INSERT
INTO    "mytable"
VALUES  (2);

SELECT  *
FROM    mytable;

---
  2

SELECT  *
FROM    MYTABLE;

---
  2

两个查询都将返回 2,因为它们是针对 "mytable" 发出的,而不是针对 >“我的表”

要返回 1(即针对 "MYTABLE" 发出查询,而不是 "mytable"),您需要引用它:

SELECT  *
FROM    "MYTABLE";

---
  1

CREATE TABLE 等不是标识符,它们是保留字。

您可以在任何您喜欢的情况下使用它们。

In PostgreSQL, an unquoted identifier is converted into lowercase:

CREATE TABLE "MYTABLE" (id INT NOT NULL);

CREATE TABLE "mytable" (id INT NOT NULL);

INSERT
INTO    "MYTABLE"
VALUES  (1);

INSERT
INTO    "mytable"
VALUES  (2);

SELECT  *
FROM    mytable;

---
  2

SELECT  *
FROM    MYTABLE;

---
  2

Both queries will return 2, since they are issued against "mytable", not "MYTABLE".

To return 1 (i. e. issue a query against "MYTABLE", not "mytable"), you need to quote it:

SELECT  *
FROM    "MYTABLE";

---
  1

CREATE TABLE etc. are not identifiers, they are reserved words.

You can use them in any case you like.

彼岸花ソ最美的依靠 2024-08-05 05:16:29

不,我认为这位先生提到使用所有小写标识符,例如表、列等名称。 这应该不会影响您使用的 CREATE TABLE 等命令。

马克

No, I think the gentleman referred to using all lowercase identifiers, e.g. table, column etc. names. This should have no impact on the commands like CREATE TABLE etc. that you use.

Marc

你没皮卡萌 2024-08-05 05:16:29

我不知道他为什么这么说。 至少在 SQL Server 中,标识符的大小写并不重要。 也许在其他 DBMS 系统中也是如此?

I have no idea why he said that. In SQL Server, at least, the case of an identifier doesn't matter. Maybe it does in other DBMS systems?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文