Restore with no data

  • Can I do a restore without restoring the data in the tables?

    Thinking there should be an option to see in this restore code...

    RESTORE DATABASE [PLC_LIVE] FROM

    DISK = N'filelocation\x.BAK' WITH FILE = 1,

    NOUNLOAD, REPLACE, STATS = 10

    GO

  • Not with native SQL Server backup and restore. You can script tables in Enterprise Manager or Query Analyzer and run the script to create tables without data or you can use the "Copy objects and data..." option in the DTS Import/Export Wizard to create tables without copying data.

    Greg

    Greg

  • Here's the deal - we had a problem a few weeks ago and one of the guys deleted the log file. So, we created a new Database same name on different server. It doesn't have alot of room so the restore won't work there. All I really need is the table structure and stored procedures.

    So, a moment ago I tried deleting the original database and it gave me an error 'alter database is not permitted while a database is in the restoring state' - how do I stop that. My guess is another IT person here tried a restore - and so it's been sitting in limbo for who knows how long. How do I stop that?

  • Hi,

    From Bol

    http://msdn2.microsoft.com/en-us/library/ms174269.aspx

    When a database is in the RESTORING state, most ALTER DATABASE statements will fail. The exception is setting database mirroring options. A database may be in the RESTORING state during an active restore operation or when a restore operation of a database or log file fails because of a corrupted backup file.For more information, see Responding to SQL Server Restore Errors Caused by Damaged Backups

    Regards,

    Ahmed

  • Since you are going to restore the database again anyway, you could try:

    RESTORE DATABASE dbname WITH RECOVERY

    That should bring the database online. Then you can delete it & try again.



    Scott Duncan

    MARCUS. Why dost thou laugh? It fits not with this hour.
    TITUS. Why, I have not another tear to shed;
    --Titus Andronicus, William Shakespeare


  • As Scott said, RESTORE DATABASE dbname WITH RECOVERY, this will remove the database from a recovering state. Delete the database. Then restore from backup.

  • So, it's still not really clear to me... I want to attach to a db (very large, sql 2000) on another server and create an empty db on the new server (which is sql 2005) which has limited disk space. What is the best way to do this? Is there a way to restore with no data?

    In addition, I require a subset of data. To get a subset I'll likely have to copy the extract sql and use that to create an extract script of my own for testing. Better ideas?

    Thanks

  • The 'brute force' or 'inelegant' way of solving your problem is to copy your backup to a second version of the db on the 2000 server, delete all data (truncate?), and back up that database. Then port the 'empty' backup over to your sql2005 server and load the structure. Alternatively, it's attempting to capture all the scripts only to recreate an empty database.

    I know there are some interesting options that allow you to capture information about the backup, without actually performing a backup, but you want to perform a 'hybrid' backup of structures and programs only.

    Alternatively, you could create a publication, if the two servers can talk to each other, and put filters on each article to send 0 data over. But this is another flavor of a brute force solution.

    In 2000, DTS allows you to script out the database without too much difficulty, if I remember correctly from a thread on the replication forum - that may be your best route.

  • I haven't been on 2000 in a little while, but I think you can script out all the objects from your production database to a single .SQL file. Then create a new database. Then run that script in your new empty database to create empty tables, SPs, views etc...

  • Thanks for your suggestions. DTS was giving me failures on copying some of the objects.... This db has multiple file groups, anyway, never made it past the failure. (and it said copy files and data where I only wanted files). There are multiple file groups, which may be an issue in itself?

    The db is too big to do anything with as far as moving, copying etc. And we don't have enough extra space on ANY server! 17 gig db with only a few gig available at the best of times on the current db server. I know.... not the best situation, but it's why we are moving to a new 64 bit server.

    I will try the scripting method, it might take all day to get a script but it's likely my only option. Then do I have to fix the logins for sql 2005?

    Thanks again in advance for your help. If we were given the appropriate disk space none of this would really be an issue at all! 🙂

  • Object level Recovery tool in LiteSpeed SQL is the solution.

  • SQL Compare 7 from Red Gate Software will allow you to do that. Create an empty database and then compare the backup file to this empty database.

    SQL BAK Explorer - read SQL Server backup file details without SQL Server.
    Supports backup files created with SQL Server 2005 up to SQL Server 2017.

Viewing 12 posts - 1 through 11 (of 11 total)

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