Primary Key 跟 Table 可以在不同的 File Group

use Northwind
go
ALTER DATABASE [Northwind] ADD FILEGROUP [fg]
ALTER DATABASE [Northwind] ADD FILE
( NAME = N’Northwind1′, FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Northwind1.ndf’  )
TO FILEGROUP [fg]

CREATE TABLE t(c1 int not null,c2 int)

CREATE CLUSTERED INDEX idx ON t(c1) ON [PRIMARY]

ALTER TABLE t ADD CONSTRAINT pk PRIMARY KEY(c1) ON fg

SELECT o.[name], o.[type], i.[name], i.[index_id], f.[name]
FROM sys.indexes i JOIN sys.filegroups f ON i.data_space_id = f.data_space_id
INNER JOIN sys.all_objects o ON i.[object_id] = o.[object_id]
AND o.name=’t’

image

DROP TABLE t

ALTER DATABASE [Northwind]  REMOVE FILE [Northwind1]
GO
ALTER DATABASE [Northwind] REMOVE FILEGROUP [fg]
GO

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: