SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Restore Database with any number of Ndf files


Restore Database with any number of Ndf files

Author
Message
Sanjeev. Kumar
Sanjeev. Kumar
SSC-Enthusiastic
SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)

Group: General Forum Members
Points: 127 Visits: 107
Comments posted to this topic are about the item Restore Database with any number of Ndf files
ppnrao99
ppnrao99
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 52
I get the following error when trying to run the restore command:

Msg 213, Level 16, State 7, Line 1
Column name or number of supplied values does not match table definition.
Msg 3013, Level 16, State 1, Line 1
RESTORE FILELIST is terminating abnormally.
Sanjeev. Kumar
Sanjeev. Kumar
SSC-Enthusiastic
SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)

Group: General Forum Members
Points: 127 Visits: 107
What query have you executed?
ppnrao99
ppnrao99
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 52
I have created the stored procedure in Master, then ran the following command:
exec sp_restoredb N'mydatabase', N'D:\mydatabase.bak'
Sanjeev. Kumar
Sanjeev. Kumar
SSC-Enthusiastic
SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)

Group: General Forum Members
Points: 127 Visits: 107
If you are executing
exec sp_restoredb N'mydatabase', N'D:\mydatabase.bak'

it means database on which you want to do restore is mydatabase with mdf,ldf and one or more ndf files and backup using which you want to do restore operation is mydatabase.bak(having same number of ndf files as that of my database on which restore will occur).Kindly check this, it its fine then no error may occur while execution.
ppnrao99
ppnrao99
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 52
Here are the steps I have followed:
1.Took a full back up of an existing database (abc.bak)
2.Executed your script, but using entirely new database name thinking that it will create a new database and restores the data from the backup.
So your script works only if the target database already exists. I was thinking even if it doesn't exist it will create a database with new name.

PLEASE CLARIFY MY UNDERSTANDING IS CORRECT.
Sanjeev. Kumar
Sanjeev. Kumar
SSC-Enthusiastic
SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)

Group: General Forum Members
Points: 127 Visits: 107
It will restore on existing database only.
philip.lind
philip.lind
SSC-Enthusiastic
SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)

Group: General Forum Members
Points: 160 Visits: 94
And it won't restore a database backup that has more files than the database you're replacing.
I have been using the following code for generating the 'move' parameters, which handles this situation by putting new files in the default file path:


DECLARE @Move nvarchar(max);
SET @Move = NULL
SELECT @Move = COALESCE(@Move + ',
', ' ') + 'MOVE N''' + lfn.LogicalName + ''' TO N'''
+ COALESCE(mf.physical_name, -- Use filename and path from existing file
-- Or put new files in 'default paths':
CASE lfn.[Type]
WHEN 'D' THEN CONCAT(CONVERT(nvarchar(max), SERVERPROPERTY('instancedefaultdatapath')), LogicalName, '.mdf')
WHEN 'L' THEN CONCAT(CONVERT(nvarchar(max), SERVERPROPERTY('instancedefaultlogpath')), LogicalName, '.ldf')
END
) + ''''
FROM #logicalfilenames lfn
LEFT JOIN (
SELECT DatabaseName = d.name, mf.name, mf.physical_name
FROM sys.master_files mf
JOIN sys.databases d ON d.database_id = mf.database_id
) mf ON mf.name = lfn.LogicalName AND mf.DatabaseName = @dbname


Iwas Bornready
Iwas Bornready
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18964 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search