SQL Server 파일그룹 생성 방법, 테이블 생성 시 파일 그룹 지정하기, 파일그룹 정보 확인, 테이블이 어떤 파일그룹에 포함되어 있는지 검색하는 방법에 대해서 아래와 같이 정리하였습니다.
USE master
GO
IF DB_ID (N'LAIGO2009') IS NOT NULL
DROP DATABASE LAIGO2009
CREATE DATABASE LAIGO2009
ON PRIMARY
( NAME = LAIGO_DATA1, FILENAME = 'D:\05.SQL\LAIGO_DATA1.mdf', SIZE = 3MB, FILEGROWTH = 2MB),
( NAME = LAIGO_DATA2, FILENAME = 'D:\05.SQL\LAIGO_DATA2.ndf', SIZE = 3MB, FILEGROWTH = 2MB),
FILEGROUP SECONDARY
( NAME = LAIGO_DATA3, FILENAME = 'D:\05.SQL\LAIGO_DATA3.ndf', SIZE = 3MB, FILEGROWTH = 2MB),
( NAME = LAIGO_DATA4, FILENAME = 'D:\05.SQL\LAIGO_DATA4.ndf', SIZE = 3MB, FILEGROWTH = 2MB)
LOG ON
( NAME = LAIGO_LOG, FILENAME = 'D:\05.SQL\LAIGO_LOG.ldf', SIZE = 100MB, FILEGROWTH = 10MB)
USE LAIGO2009
GO
CREATE TABLE X (A CHAR(30), B INT)
DECLARE @COUNT_X INT
SELECT @COUNT_X=0
WHILE @COUNT_X<200000
BEGIN
SELECT @COUNT_X=@COUNT_X+1
INSERT X VALUES(CONVERT (CHAR(30), @COUNT_X), @COUNT_X)
END
CREATE TABLE Y (C CHAR(30), D INT) ON SECONDARY
DECLARE @COUNT_Y INT
SELECT @COUNT_Y=0
WHILE @COUNT_Y<200000
BEGIN
SELECT @COUNT_Y=@COUNT_Y+1
INSERT Y VALUES(CONVERT (CHAR(30), @COUNT_Y), @COUNT_Y)
END
sp_helpdb LAIGO2009
sp_helpfilegroup secondary
sp_help y
SELECT A.Name, C.GroupName FROM sys.sysobjects AS A INNER JOIN sys.sysindexes AS B ON A.id = B.id INNER JOIN sys.sysfilegroups AS C ON B.groupid = C.groupid WHERE A.name = 'Y'
GO
IF DB_ID (N'LAIGO2009') IS NOT NULL
DROP DATABASE LAIGO2009
CREATE DATABASE LAIGO2009
ON PRIMARY
( NAME = LAIGO_DATA1, FILENAME = 'D:\05.SQL\LAIGO_DATA1.mdf', SIZE = 3MB, FILEGROWTH = 2MB),
( NAME = LAIGO_DATA2, FILENAME = 'D:\05.SQL\LAIGO_DATA2.ndf', SIZE = 3MB, FILEGROWTH = 2MB),
FILEGROUP SECONDARY
( NAME = LAIGO_DATA3, FILENAME = 'D:\05.SQL\LAIGO_DATA3.ndf', SIZE = 3MB, FILEGROWTH = 2MB),
( NAME = LAIGO_DATA4, FILENAME = 'D:\05.SQL\LAIGO_DATA4.ndf', SIZE = 3MB, FILEGROWTH = 2MB)
LOG ON
( NAME = LAIGO_LOG, FILENAME = 'D:\05.SQL\LAIGO_LOG.ldf', SIZE = 100MB, FILEGROWTH = 10MB)
USE LAIGO2009
GO
CREATE TABLE X (A CHAR(30), B INT)
DECLARE @COUNT_X INT
SELECT @COUNT_X=0
WHILE @COUNT_X<200000
BEGIN
SELECT @COUNT_X=@COUNT_X+1
INSERT X VALUES(CONVERT (CHAR(30), @COUNT_X), @COUNT_X)
END
CREATE TABLE Y (C CHAR(30), D INT) ON SECONDARY
DECLARE @COUNT_Y INT
SELECT @COUNT_Y=0
WHILE @COUNT_Y<200000
BEGIN
SELECT @COUNT_Y=@COUNT_Y+1
INSERT Y VALUES(CONVERT (CHAR(30), @COUNT_Y), @COUNT_Y)
END
sp_helpdb LAIGO2009
sp_helpfilegroup secondary
sp_help y
SELECT A.Name, C.GroupName FROM sys.sysobjects AS A INNER JOIN sys.sysindexes AS B ON A.id = B.id INNER JOIN sys.sysfilegroups AS C ON B.groupid = C.groupid WHERE A.name = 'Y'
[참고자료]
파일 및 파일 그룹 이해
http://msdn.microsoft.com/ko-kr/library/ms189563.aspx
작성자 : Lai Go / 작성일자 : 2009.12.09