Luk*_*zda 7 sql t-sql sql-server create-table sql-server-2017
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';
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法使用内联索引定义创建相同的构造:
CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t(col));
Run Code Online (Sandbox Code Playgroud)
Msg 2714 Level 16 State 5 Line 1
数据库中已经有一个名为"t"的对象.
-- below code is working correctly
CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t1(col));
Run Code Online (Sandbox Code Playgroud)
我是否会错过一些明显的或者是一个错误?
我是否会错过一些明显的或者是一个错误?
看起来像个bug.
CREATE TABLE t(id INT PRIMARY KEY, col INT, INDEX t(col));
Run Code Online (Sandbox Code Playgroud)
输出
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.
Run Code Online (Sandbox Code Playgroud)
请在此处添加反馈项:https://feedback.azure.com/forums/908035-sql-server 特别注意到这是SQL 2016中的回归.