简体   繁体   中英

Files and filegroups sql server 2005

Can we move default file to another filegroup. sample code is given below

Sample code

create database EMPLOYEE
ON PRIMARY
(
NAME = 'PRIMARY_01',
FILENAME = 'C:\METADATA\PRIM01.MDF',
SIZE = 5 MB ,
MAXSIZE =50 MB,
FILEGROWTH = 2 MB),
(
NAME = 'SECONDARY_02',
FILENAME = 'C:\METADATA\SEC02.NDF'
),

FILEGROUP EMPLOYEE_dETAILS
(
NAME = 'EMPDETILS_01',
FILENAME = 'C:\METADATA\EMPDET01.NDF',
SIZE = 5 MB ,
MAXSIZE =50 MB,
FILEGROWTH = 2 MB),
(
NAME = 'EMPDETILS_02',
FILENAME = 'C:\METADATA\EMPDET02.NDF',
SIZE = 5 MB ,
MAXSIZE =50 MB,
FILEGROWTH = 2 MB)

LOG ON
(
NAME = 'TRANSACLOG',
FILENAME ='c:\METADATA\TRAS01.LDF',
SIZE = 5 MB ,
MAXSIZE =50 MB,
FILEGROWTH = 2 MB
)
now i want to move the
 FILENAME = 'C:\\METADATA\\SEC02.NDF' from deault primary file to the FILEGROUP EMPLOYEE_dETAILS ? 

need assist ??

This cannot be done. A file group will "contain" one or more files, and those files host the data stored within the filegroup in (or so I've heard) a round-robin fashion -- think of the data as being spread evenly between all files. You can direct which file group your data will be stored in, but you have no control over which file within that file group any particular bit of data will be written to. If you somehow moved a file from one file group to another, you'd be moving a random half of that file group's data to another file group that wouldn't know what to do with it, and that would permanently corrupt your database.

What are you actually trying to do? Move data stored in a file group into another file group? Remove a file from a file group? Add a file to a file group? (The first can be done by creating a new object in the target file group, copying the data over, dropping the old object, and renaming the new object; the second two can be done via the ALTER DATABASE command.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM