How to take a SQL Server Database Full Backup

 
How to take a SQL Server Database Full Backup


Use master
go
 

Create database Sales
go
 
use sales
go
 
 
Create table Products
(ProductID int IDENTITY (1,1) Primary Key,
ProductName varchar (100),
Brand varchar (100))
go
 
insert into Products values ('Bike','Genesis')
insert into Products values ('Hat','Nike')
insert into Products values ('Shoe','Payless')
insert into Products values ('Phone','Apple')
insert into Products values ('Book','Green')
insert into Products values ('Cup','Large')
 
select * from Products
BACKUP DATABASE [sales]
TO  DISK = N'I:\backup\sales.bak'
WITH NOINIT,
NAME = N'sales-Full Database Backup',
COMPRESSION,
STATS = 10
GO
 

declare @backupSetId as int
select @backupSetId = position
from msdb..backupset
where database_name=N'sales'
and backup_set_id=(select max(backup_set_id)
from msdb..backupset where database_name=N'sales' )
if @backupSetId is null
begin
raiserror(N'Verify failed. Backup information for database ''sales'' not found.', 16, 1)
end
RESTORE VERIFYONLY
FROM
DISK = N'I:\backup\sales.bak'
WITH  FILE = @backupSetId
GO

Use msdb
go

SELECT * FROM dbo.backupfile  -- Contains one row for each data or log file that is backed up
SELECT * FROM dbo.backupmediafamily  -- Contains one row for each media family
SELECT * FROM dbo.backupmediaset -- Contains one row for each backup media set
SELECT * FROM dbo.backupset  -- Contains a row for each backup set
SELECT * FROM dbo.backupfilegroup -- Contains one row for each filegroup in a database at the time of backup

Comments