我使用此脚本将表从具有一个数据文件的主文件组移动到具有四个数据文件的另一个文件组 [FG]:
/* CREATE FILEGROUP FG*/
USE [master]
GO
ALTER DATABASE [DEV_DATABASE] ADD FILEGROUP [FG]
GO
/* CREATE 4 DATAFILES INTO FG*/
USE [master]
GO
ALTER DATABASE [DEV_DATABASE]
ADD FILE ( NAME = N'DEV_DATABASE01', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\DEV_DATABASE01.ndf' , SIZE = 2000000kB , FILEGROWTH = 524288KB ),
( NAME = N'DEV_DATABASE02', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\DEV_DATABASE02.ndf' , SIZE = 2000000KB , FILEGROWTH = 524288KB ),
( NAME = N'DEV_DATABASE03', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\DEV_DATABASE03.ndf' , SIZE = 2000000KB , FILEGROWTH = 524288KB ),
( NAME = N'DEV_DATABASE04', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\DEV_DATABASE04.ndf' , SIZE = 2000000KB , FILEGROWTH = 524288KB )
TO FILEGROUP [FG]
GO
/*DROP CLUSTERED INDEX*/
USE DEV_DATABASE
GO
ALTER TABLE TRANS_TABLE
DROP CONSTRAINT PK__TRANS_TAB__F27DAC7609A3C91A WITH (MOVE TO FG)
/* CREATE PRIMARY KEY INTO FG FILEGROUP */
USE DEV_DATABASE
GO
ALTER TABLE TRANS_TABLE
ADD CONSTRAINT PK__TRANS_TAB__F27DAC7609A3C91A PRIMARY KEY (ID) ON FG;
/* CREATE CLUSTERED INDEX IN FG FILEGROUP */
USE DEV_DATABASE
GO
CREATE UNIQUE CLUSTERED INDEX PK__TRANS_TAB__F27DAC7609A3C91A ON TRANS_TABLE (ID)
WITH (DROP_EXISTING = ON)
ON FG
当我检查(主文件组的)数据文件大小时,我意识到它并没有减少,并且 4 个数据文件(FG 文件组)的大小增加了。现在我想从主数据文件(主文件组)中释放空间。如何处理这个问题?