gpt4 book ai didi

sql - 当名称与表名相同时,内联索引定义失败

转载 作者:行者123 更新时间:2023-12-02 16:14:39 24 4
gpt4 key购买 nike

SQL Server 对象(即表和索引)有自己的命名空间。因此索引和表可以具有相同的名称(但这不是常见/好的做法):

CREATE TABLE t(id INT PRIMARY KEY, col INT);
CREATE INDEX t ON t(col);

SELECT * FROM sys.tables WHERE name = 't';
SELECT * FROM sys.indexes WHERE name = 't';

<强> db<>fiddle demo

不幸的是,我无法使用inline index definition创建相同的构造。 :

CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t(col));

Msg 2714 Level 16 State 5 Line 1

There is already an object named 't' in the database.

-- below code is working correctly
CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t1(col));

<强> db<>fiddle demo 2

我错过了一些明显的事情还是一个错误?

最佳答案

Do I miss something obvious or is it a bug?

看起来像一个错误。

CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t(col));

输出

Microsoft SQL Server 2017 (RTM-GDR) (KB4293803) - 14.0.2002.14 (X64) 
Jul 21 2018 07:47:45
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 17763: ) (Hypervisor)


(1 row affected)

Msg 2714, Level 16, State 5, Line 4
There is already an object named 't' in the database.
Msg 1750, Level 16, State 1, Line 4
Could not create constraint or index. See previous errors.

请在此处添加反馈项:https://feedback.azure.com/forums/908035-sql-server特别要注意的是,这是 SQL 2016 中的回归。

关于sql - 当名称与表名相同时,内联索引定义失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54118897/

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