How to dynamically create my FILEGROUP during a restore?

  • How can I dynamically create my FILEGROUP during a restore?

    My FILELISTONLY renders

    [font="Courier New"]LogicalName PhysicalName Type FileGroupName

    =========== ============ ==== =============

    MyDBData_Primary G:\SQLData\Archive_Primary.mdf D PRIMARY

    MyDBData_1 G:\SQLData\MyDB_1.ndf D DataFileGroup

    MyDBData_2 G:\SQLData\MyDB_2.ndf D DataFileGroup

    MyDBLog L:\SQLLogs\MyDB.ldf L NULL[/font]

    How can I tweak the following RESTORE command to dynamically generate the FileGroupName called 'DataFileGroup' listed above?

    RESTORE DATABASE MyDB FROM DISK='H:\SQLBACKUPS\MyDB.bak'

    WITH RECOVERY, REPLACE,

    MOVE 'MyDBData_Primary' TO 'E:\SQLData\MyDB_Primary.mdf',

    MOVE 'MyDBData_1' TO 'E:\SQLData\MyDB_1.ndf',

    MOVE 'MyDBData_2' TO 'E:\SQLData\MyDB_2.ndf',

    MOVE 'MyDBLog' TO 'F:\SQLLogs\MyDB.ldf'

    GO

    BT
  • You don't need to. The restore will create an exact copy of the database, including filegroups.

    John

  • John - thanks. Right on w/ your reply. The restore created the FG. Appreciate your feedback.

    BT

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply