gpt4 book ai didi

sql-server - SQL Server 中外键是否自动建立索引?

转载 作者:行者123 更新时间:2023-12-01 17:29:20 25 4
gpt4 key购买 nike

以下 SQL 语句会自动在 Table1.Table1Column 上创建索引,还是必须显式创建索引?

数据库引擎是SQL Server 2000

       CREATE TABLE [Table1] (
. . .
CONSTRAINT [FK_Table1_Table2] FOREIGN KEY
(
[Table1Column]
) REFERENCES [Table2] (
[Table2ID]
)

)

最佳答案

SQL Server 不会自动在外键上创建索引。同样来自 MSDN:

A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table. A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, verification of all values that make up the FOREIGN KEY constraint is skipped. To make sure that all values of a composite FOREIGN KEY constraint are verified, specify NOT NULL on all the participating columns.

关于sql-server - SQL Server 中外键是否自动建立索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/278982/

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