Sie sind auf Seite 1von 21

SQL Server 2008 R2 Database Creation, Doing Manual Backup And Automate

Backup
Links ......................................................................................................................................................... 2
SQL Server Tools in 2008 R2 .................................................................................................................... 2
Creating a Database ................................................................................................................................ 2
Using T-SQL Database Creation ............................................................................................................... 3
T-SQL for Creating Database ................................................................................................................... 3
Database Properties ................................................................................................................................ 5
Creating A Database Owner Account ...................................................................................................... 6
Security Folders ....................................................................................................................................... 9
Backup of the Database......................................................................................................................... 11
Manual Backup ...................................................................................................................................... 13
Differential Backup ................................................................................................................................ 18
Automating Backup ............................................................................................................................... 19

Links

Below is the link for creating SQL Server Instance in 2008 R2


https://de.scribd.com/doc/251464815/SQLServer-2008R2-Database-Instance-Installationdetailed-pdf
An instance should be created before a database is created

SQL Server Tools in 2008 R2

Below are the most often used Tools in SQL Server 2008 R2

Creating a Database

This is a fresh Database creation and the screenshots below show what will be saved in
these folders once a Database is created.

The Log file will be present here once the database is created

Using T-SQL Database Creation

If you prefer to create Database using GUI then right click on "Databases" select "New
Database"
Below is using Command line which is also a good thing to practise. Below is the screenshot
and next to it is the T-SQL to create database. Select all the lines and press "Execute" Button

T-SQL for Creating Database

Click on "New Query" Button to write T-SQL and change the Paths as suitable to you

USE [master]
GO
CREATE DATABASE [EuropeDB]

ON

PRIMARY

( NAME = N'MainDatafile', FILENAME =


N'G:\EUR2070\UserData\MainDatafile.mdf' , SIZE = 25600KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB ),
FILEGROUP [CustomersEurope]
( NAME = N'CustomerFile01', FILENAME =
N'G:\EUR2070\UserData\CustomerFile01.ndf' , SIZE = 5120KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB ),
( NAME = N'CustomersFile02', FILENAME =
N'G:\EUR2070\UserData\CustomersFile02.ndf' , SIZE = 5120KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'EuropeDB_log', FILENAME =
N'H:\EUR2070\Log\EuropeDB_log.ldf' , SIZE = 10240KB , MAXSIZE = 2048GB ,
FILEGROWTH = 10%)
GO

Files in the folders after the creation of Database

Click on "Refresh" Button to see the Database, which is highlighted below if you do not see
the Database

Database Properties

Right click on this newly created Database and then on Properties


In the below screen you see "CustomersEurope" which is a File Group. if you check this and
mark as Default then the User created Tables will be saved here by default

None would save everything on one File and consider as that as Storage for data. So, Files
and Filegroups is the way to go and store the data

Creating A Database Owner Account

The Database Role "db_owner" makes a User Account a demy God of the database
In this procedure AD (Active Directory) Account is not used
Right click on Users to create an Account . The below screens shows it

Every System Database and User Database has a "Security" folder


Right click on "Logins" that's in the "Security" folder. Type the account name in the "Login
name" and click the button next to it and finally on "Check Names"
The default Database for this User points to "Master Database". In this case the default for
this User is "EuropeDB" but not Master Database. Change it to "EuropeDB" Database

Click on User Mapping to assign Database Roles to this User Account. In this Test the User
has other roles too that are "data_reader" and "data_writer" along with "db_owner"
Database Role

Login to the System using this account and connect the Database
Finally create a test Schema and Table to see whether User has the rights to create Data and
Read Data from this Database

Security Folders

Below is the screenshot that shows the existence of a Security Folder for an Instance, System
Databases and User Database

The main purpose of it is quite straight. If an account exists in these Security Folder then
there is access to a User

Using Powershell it is possible to navigate to each Role

Backup of the Database

Using GUI, right click on this newly created Database and on 'Properties'. The General Tab
shows when was the last time a Backup was made for a Database

Let's create an account that is used for Backup of all the Databases of this Instance
Creating an account to shown in "Creating A Database Owner Account". Just create an
account and then double click the account to assign relevant "Roles" to this account using
SSMS Tool (SQL Server Management Studio)
In Server roles assign "sysadmin" and then click on "User Mapping" to assign the databases
that this User will be doing Backups
Assign "Database Backup Operator" Database Role. The User needs this Database Role for
every Database that you select

Manual Backup

Login to the System using account. Right click on the Database and click on 'Properties' to see
when was the last time a Backup was made
Doing a Backup of the Transaction Log is part of the Backup

Navigate as shown below to do a Manual Backup


The below screens shows the steps

Master Database Backup

User Database Backup that is "EuropeDB" in this case and the Recovery Model is "Full"

Backup of Transaction Log and the Recovery Model is "Full"

Verify of the Backup. Navigate to this folder to verify the existence of Backup

Differential Backup

What we did in latter step was a Full Backup. See the "Recovery Model" in the above screens
In the below screens it is about doing the Differential Backup

Automating Backup

Each time it is not possible to do a Manual Backup watching the Clock so the backups needs
to be automated
Below is the basic overview of automating the backup
Showing the initial screens how a Backup can be automated

Das könnte Ihnen auch gefallen