ON [CommonData] 定义了用于物理存储数据的file group。
您在问题中使用的语法为聚集索引和表定义了它。不过,它们实际上并不是两个独立的实体。聚集索引是表。
您可以省略其中任何一个,最终得到相同的结果。该表被创建为文件组 CommonData 上的聚集索引,并且如果未明确指定,则在该文件组上创建该表上的任何非聚集索引。
即下面的两次尝试都返回相同的结果
+--------------+------------+
| name | name |
+--------------+------------+
| PK_Some_name | CommonData |
| ix_field3 | CommonData |
| ix_field2 | CommonData |
+--------------+------------+
drop TABLE if exists dbo.table_name
go
CREATE TABLE dbo.[table_name] (
[field1] [int] not null,
[field2] [int] not null,
[field3] [int] not null INDEX ix_field3, /*Not specifying filegroup*/
CONSTRAINT [PK_Some_name] PRIMARY KEY CLUSTERED ([field1] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
) ON CommonData
CREATE INDEX ix_field2 ON dbo.[table_name]([field2]) /*Not specifying filegroup*/
SELECT i.name, ds.name
FROM sys.indexes i
JOIN sys.data_spaces ds on ds.data_space_id = i.data_space_id
WHERE object_id = object_id('dbo.table_name')
GO
drop TABLE if exists dbo.table_name
go
CREATE TABLE dbo.[table_name] (
[field1] [int] not null,
[field2] [int] not null,
[field3] [int] not null INDEX ix_field3, /*Not specifying filegroup*/
CONSTRAINT [PK_Some_name] PRIMARY KEY CLUSTERED ([field1] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON CommonData
)
CREATE INDEX ix_field2 ON dbo.[table_name]([field2]) /*Not specifying filegroup*/
SELECT i.name, ds.name
FROM sys.indexes i
JOIN sys.data_spaces ds on ds.data_space_id = i.data_space_id
where object_id = object_id('dbo.table_name')