생각했던 것보다 용량이 크게 필요하네...음....
use master
GO
--1) 기존 DB 삭제를 위한 사용자 제한
ALTER DATABASE TEST SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--2) DB 삭제(테스트 용도)
DROP DATABASE TEST
GO
--3) DB 생성 (수기 작업이 제일 깔끔함)
--4) 파일 그룹 생성
ALTER DATABASE [TEST] ADD FILEGROUP [FG1];
ALTER DATABASE [TEST] ADD FILEGROUP [FG2];
ALTER DATABASE [TEST] ADD FILEGROUP [FG3];
ALTER DATABASE [TEST] ADD FILEGROUP [FG4];
ALTER DATABASE [TEST] ADD FILEGROUP [FG5];
ALTER DATABASE [TEST] ADD FILEGROUP [FG6];
ALTER DATABASE [TEST] ADD FILEGROUP [FG7];
ALTER DATABASE [TEST] ADD FILEGROUP [FG8];
ALTER DATABASE [TEST] ADD FILEGROUP [FG9];
ALTER DATABASE [TEST] ADD FILEGROUP [FG10];
ALTER DATABASE [TEST] ADD FILEGROUP [FG11];
ALTER DATABASE [TEST] ADD FILEGROUP [FG12];
ALTER DATABASE [TEST] ADD FILEGROUP [FG13];
--5) 작업을 위한 DB 설정
Alter DATABASE [TEST] SET RECOVERY SIMPLE;
--6) 파일그룹 연결
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_1', FILENAME = N'D:\PartitionGroup\FG_1.ndf') TO FILEGROUP [FG1];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_2', FILENAME = N'D:\PartitionGroup\FG_2.ndf') TO FILEGROUP [FG2];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_3', FILENAME = N'D:\PartitionGroup\FG_3.ndf') TO FILEGROUP [FG3];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_4', FILENAME = N'D:\PartitionGroup\FG_4.ndf') TO FILEGROUP [FG4];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_5', FILENAME = N'D:\PartitionGroup\FG_5.ndf') TO FILEGROUP [FG5];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_6', FILENAME = N'D:\PartitionGroup\FG_6.ndf') TO FILEGROUP [FG6];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_7', FILENAME = N'D:\PartitionGroup\FG_7.ndf') TO FILEGROUP [FG7];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_8', FILENAME = N'D:\PartitionGroup\FG_8.ndf') TO FILEGROUP [FG8];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_9', FILENAME = N'D:\PartitionGroup\FG_9.ndf') TO FILEGROUP [FG9];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_10', FILENAME = N'D:\PartitionGroup\FG_10.ndf') TO FILEGROUP [FG10];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_11', FILENAME = N'D:\PartitionGroup\FG_11.ndf') TO FILEGROUP [FG11];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_12', FILENAME = N'D:\PartitionGroup\FG_12.ndf') TO FILEGROUP [FG12];
ALTER DATABASE [TEST] ADD FILE (NAME = N'FG_13', FILENAME = N'D:\PartitionGroup\FG_13.ndf') TO FILEGROUP [FG13];
--7) 파티션 FUNCTION 생성
USE TEST;
GO
CREATE PARTITION FUNCTION [FG_FUNCTION](datetime) AS RANGE LEFT FOR VALUES
(N'2012-12-31 23:59:59.997', N'2013-12-31 23:59:59.997', N'2014-12-31 23:59:59.997', N'2015-12-31 23:59:59.997', N'2016-12-31 23:59:59.997', N'2017-12-31 23:59:59.997',
N'2018-12-31 23:59:59.997', N'2019-12-31 23:59:59.997', N'2020-12-31 23:59:59.997', N'2021-12-31 23:59:59.997', N'2022-12-31 23:59:59.997', N'2023-12-31 23:59:59.997');
CREATE PARTITION FUNCTION [FG_FUNCTION2](bigint) AS RANGE LEFT FOR VALUES
(2000, 4000, 6000, 8000, 10000, 12000);
--8) 파티션 SCHEME 생성
USE TEST;
GO
CREATE PARTITION SCHEME [FG_FUNCTION_SCH] AS PARTITION [FG_FUNCTION] TO ([FG1],[FG2],[FG3],[FG4],[FG5],[FG6],[FG7],[FG8],[FG9],[FG10],[FG11],[FG12],[FG13]);
CREATE PARTITION SCHEME [FG_FUNCTION_SCH2] AS PARTITION [FG_FUNCTION2] TO ([FG1],[FG2],[FG3],[FG4],[FG5],[FG6],[FG7]);
-- 파티션 적용
-- 테이블 생성시 ON [파티션SCHEME] (대상컬럼)
'MS-SQL' 카테고리의 다른 글
VARCHAR, NVARCHAR (0) | 2022.08.19 |
---|---|
[MS-SQL] LIKE 검색이 안된다? (0) | 2022.07.25 |
[MS-SQL] LEFT OUTER JOIN 시에 ON 절과 WHERE 절에 추가 제약조건 넣는 규칙! (0) | 2021.02.04 |
[MS-SQL] 임시 테이블 VS 변수 테이블 (0) | 2019.07.30 |
[MSSQL] TABLE 정보 쉽게 확인하기 (0) | 2018.11.05 |