30.06.2013 Views

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: File <strong>and</strong> Filegroup <strong>Backup</strong> <strong>and</strong> <strong>Restore</strong><br />

USE [DatabaseForFile<strong>Backup</strong>s_SB]<br />

GO<br />

INSERT INTO Table_DF2<br />

VALUES ( 'This is the third data load for Table_DF2' )<br />

GO<br />

Listing 9-26: Third data load for DatabaseForFile<strong>Backup</strong>s_SB.<br />

Now we're going to simulate a problem with our secondary data file which takes it<br />

(<strong>and</strong> our database) offline; in Listing 9-27 we take the database offline. Having done so,<br />

navigate to the C:\<strong>SQL</strong>Data\Chapter9 folder <strong>and</strong> delete the secondary data file!<br />

-- Take DatabaseForFile<strong>Backup</strong>s_SB offline<br />

USE master<br />

GO<br />

ALTER DATABASE [DatabaseForFile<strong>Backup</strong>s_SB] SET OFFLINE;<br />

GO<br />

/*Now delete DatabaseForFile<strong>Backup</strong>s_SB_Data2.ndf!*/<br />

Listing 9-27: Take DatabaseForFile<strong>Backup</strong>s_SB offline <strong>and</strong> delete secondary data file!<br />

Scary stuff! Next, let's attempt to bring our database back online.<br />

USE master<br />

GO<br />

ALTER DATABASE [DatabaseForFile<strong>Backup</strong>s_SB] SET ONLINE;<br />

GO<br />

Msg 5120, Level 16, State 5, Line 1<br />

Unable to open the physical file "C:\<strong>SQL</strong>Data\DatabaseForFile<strong>Backup</strong>s_SB_Data2.ndf".<br />

Operating system error 2: "2(failed to retrieve text for this error. Reason: 15105)".<br />

Msg 945, Level 14, State 2, Line 1<br />

Database 'DatabaseForFile<strong>Backup</strong>s_SB' cannot be opened due to inaccessible files or<br />

insufficient memory or disk space. See the <strong>SQL</strong> <strong>Server</strong> errorlog for details.<br />

Msg 5069, Level 16, State 1, Line 1<br />

ALTER DATABASE statement failed.<br />

Listing 9-28: Database cannot come online due to missing secondary data file.<br />

331

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!