0% found this document useful (0 votes)
20 views12 pages

Database Administration Homework Guide

The document discusses a homework assignment on database administration. It includes questions about writing stored procedures to automate administrative tasks like inserting data, creating database profiles and accounts, creating jobs and schedules. It also discusses different types of database backups and a plan to restore data in case of data loss or server crash. Specifically: 1) It provides answers to 6 questions on writing stored procedures for tasks like inserting data, creating profiles/accounts, database backups, creating jobs and schedules. 2) It explains different types of database backups like full, differential, file/filegroup backups and discusses considerations for backup strategies based on database size. 3) It outlines a plan for restoring data including having a naming convention, backup location
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views12 pages

Database Administration Homework Guide

The document discusses a homework assignment on database administration. It includes questions about writing stored procedures to automate administrative tasks like inserting data, creating database profiles and accounts, creating jobs and schedules. It also discusses different types of database backups and a plan to restore data in case of data loss or server crash. Specifically: 1) It provides answers to 6 questions on writing stored procedures for tasks like inserting data, creating profiles/accounts, database backups, creating jobs and schedules. 2) It explains different types of database backups like full, differential, file/filegroup backups and discusses considerations for backup strategies based on database size. 3) It outlines a plan for restoring data including having a naming convention, backup location
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2010

DATABASE
ADMINISTRATION
Sub by: Mukteshwar Parbhat
Sub to: Ms. Gennia Kakkar,
Roll No: RA3803A11,
Regd No: 10810056

HOMEWORK 3

0|Page
CAP464: Administration of Database
Homework3

Date of Allocation: 07-Apr-10 Date of Submission: 22-Apr-10


Topics: Automating Administrative Tasks, Disaster Prevention and Recovery

Note 1: Attempt all questions.


Note 2: If you are assuming anything for any question, clearly mention the assumptions.

Part A

Q1. Write a stored procedure to insert data into a table “CustomerInfo” with fields
CustomerId, Customername, CustomerAddress, CustEmail, CustMobile. Supply data values
as parameters to the stored procedure. While inserting data, check in the procedure that
CustomerId is greater than zero.

Ans: Store Procedure to insert data into table “CustomerInfo”:

CREATE PROCEDURE CUST_INFO_SP2


@VAR1 INT,
@VAR2 VARCHAR(50),
@VAR3 VARCHAR(50),
@VAR4 VARCHAR(50),
@VAR5 NUMERIC(12,0)
AS
BEGIN
IF(@VAR1>0)
INSERT INTO CUSTOMERINFO VALUES (@VAR1,@VAR2,@VAR3,@VAR4,@VAR5)
END

If we enter the value less then 0 or 0 in CustomerId than the procedure will work but the
data is not inserted into the table as shown below.

Command execution:

Output:

1|Page
Now, insert data with customer id greater than 0. The data will be inserted into the table.

Command execution:

Output:

Q2. Write a stored procedure to create a database profile “MCA_PROFILE” giving an


appropriate description, and create 3 accounts for this profile “ROLLNO1”, “ROLLNO2”,
“ROLLNO3” giving email address, display name, mail server name and server type as
“SMTP”. Execute the stored procedure.

ANS: Stored Procedure to create a database profile: “MCA_PROFILE”

-- CREATING MCA PROFILE


DECLARE @PROFILE_ID INT ;
EXECUTE [Link].sysmail_add_profile_sp
2|Page
@PROFILE_NAME = 'MCA_PROFILE',
@DESCRIPTION = 'MAIL PROFILE FOR MCA',
@PROFILE_ID = @PROFILE_ID OUTPUT ;
SELECT @PROFILE_ID ;

-- INFORMATION ABOUT THE MCA PROFILE


EXEC [Link].sysmail_help_profile_sp @profile_id=1

SELECT * FROM [Link].sysmail_profile

Output:

Stored Procedure to create account for Roll No 1:

-- CREATING ACCOUNT ROLL NO 1


DECLARE @ACCOUNTID1 INT;
EXECUTE [Link].sysmail_add_account_sp
@ACCOUNT_NAME = 'ROLLNO12',
@EMAIL_ADDRESS = 'rollno1@[Link]',
@DISPLAY_NAME = 'SQL DATABASE ACCOUNT ROLLNO1',
@MAILSERVER_NAME = '[Link]',
@MAILSERVER_TYPE = 'SMTP'
SELECT @ACCOUNTID1;

Output:

Stored Procedure to create account for Roll No 2:

--CREATE ACCOUNT FOR ROLLNO2

DECLARE @ACCOUNTID1 INT;


3|Page
EXECUTE [Link].sysmail_add_account_sp
@ACCOUNT_NAME = 'ROLLNO2',
@EMAIL_ADDRESS = 'rollno2@[Link]',
@DISPLAY_NAME = 'SQL DATABASE ACCOUNT ROLLNO2',
@MAILSERVER_NAME = '[Link]',
@MAILSERVER_TYPE = 'SMTP'
SELECT @ACCOUNTID1;

Output:

Stored Procedure to create account for Roll No 3:

--CREATE ACCOUNT FOR ROLLNO3

DECLARE @ACCOUNTID1 INT;


EXECUTE [Link].sysmail_add_account_sp
@ACCOUNT_NAME = 'ROLLNO3',
@EMAIL_ADDRESS = 'rollno3@[Link]',
@DISPLAY_NAME = 'SQL DATABASE ACCOUNT ROLLNO3',
@MAILSERVER_NAME = '[Link]',
@MAILSERVER_TYPE = 'SMTP'
SELECT @ACCOUNTID1;

Output:

Adding Profile with account:

4|Page
Q3. Write a stored procedure to create a job with 2 job steps. Create a schedule for this
job to execute this job every Wednesday and Friday at 9:00AM starting from 22-Apr-10.

Ans: Store Procedure to crate a Job:

DECLARE @jobId uniqueidentifier;

EXECUTE [Link].sp_add_job
@job_name = 'MCAJOB',
@description = 'RECORD OF STUDENT PERFORMANCE IN EXAMS.',
@job_id = @jobId OUTPUT

select @jobId

Execting the job:

EXECUTE [Link].sp_add_jobserver @job_name=N'MCAJOB';

Creating Steps for Job “MCAJOB”:


5|Page
EXECUTE [Link].sp_add_jobstep
@job_name = 'MCAJOB',
@step_name = 'STEP1',
@step_id = 1,
@retry_attempts = 1,
@retry_interval = 1,
@subsystem = 'TSQL',
@command= 'SELECT * FROM MCAH WHERE TMARKS<400',
@database_name = 'hw3',
@output_file_name = 'D:\New folder\MCAHJOBDATA'

Creating the Step 2:

EXECUTE [Link].sp_add_jobstep
@job_name = 'MCAJOB',
@step_name= 'STEP2',
@step_id=2,
@retry_attempts=1,
@retry_interval=1,
@subsystem = 'TSQL',
@command = 'SELECT * FROM MCAH WHERE TMARKS>400',
@database_name = 'hw3',
@output_file_name = 'D:\New folder\MCAHJOB'

Executing the Steps of Job:

EXEC [Link].sp_update_job @job_name=N'MCAJOB',


@start_step_id = 1,
@description = 'RECORD OF STUDENT PERFORMANCE IN EXAMS.',
@on_success_action = 3;

Creating Schedule:

DECLARE @schedule_id int

EXECUTE [Link].sp_add_jobschedule
@schedule_name = ‘Weekend Schedule’,
@job_name = 'MCAJOB',
@name = 'SCH1',
@freq_type = 8,
@freq_interval = 40,
@freq_subday_type = 1,
@freq_subday_interval = 0,

6|Page
@active_start_date = 20100422,
@active_start_time = 90000,
@schedule_id = @schedule_id OUTPUT

select @schedule_id

Output: Student who score less than 400.

Output: Student who score more than 400,

Part B

Q4. Write a stored procedure “SP_BACK_DB” to take full backup of a database with
transaction log.

Ans: Store Procedure to take full backup of HW3.

7|Page
Full backup with Transaction Log.

Q5. Explicate the procedure to take different types of backup in SQL Server 2005. The
disk on your database server is crashed. Prepare a plan to restore the data.

Ans: We can take different types of backup in SQL Server 2005. These are explained below
one by one.

(i) Full Backup: In this we take full backup of our database. All transaction and updated
data is stored with records of all database location. Its advantage is that we have
full data for recovery in case of any kind of damage or data loss. But, its
disadvantage is, its size increases rapidly and it takes so much space to storage.

Procedure to take full backup:

8|Page
(ii) Differential Backup: In this kind of backup, we take full backup of database at first
time and each time after that we take the backup only that much data which is
updated or only those transaction are taken under backup which are modified.
Its benefit is we need less space and time to store the data. Its disadvantage is
that it takes lots of time to recover the data.

Procedure of Differential backup:

(iii) File/Filegroup Backup: Sometime we need to take backup of only some


necessary files or a group of files related with a specific field. At there, we can
use File/Filegroup backup. In this we can point out a particular file or filegroup,
whose backup we want to take.

Procedure to take file/filegroup backup:

9|Page
(iv) File/Filegroup with Differential: Also if we are taking regular backups, than
there are chances that we can not update the whole file on regular basis and only
a certain part of the file is update on consuctive days. Than, if we use full
File/Filegroup backup, it is totally space and storage wastage. Therefore, we can
use Differential mathod with File/ Filegroup.

Procedure of File/Filegroup with differential:

Plan to restore the data: Following points to be consider while taking backup, which helps
us to recover the data.

The manner in which you perform database backups should not be a technical decision. It
should be dictated by the business. Small systems with low transaction rates and/or
reporting systems that are loaded regularly will only ever need a full database backup.
Medium sized systems and large systems become dependent on the type of data managed
to determine what types of backup are required.

For a medium sized system, a daily backup with log backups during the day would
probably answer most data requirements in a timely manner.

For a large database the best approach is to mix and match the backups to ensure
maximum recoverability in minimum time. For example, run a weekly full backup. Twice a
day during the week, run a differential backup. Every 10 minutes during the day, run a log
backup. This gives you a large number of recovery mechanisms.

For very large databases, you'll need to get into running filegroup and file backups because
doing a full backup or even a differential backup of the full database may not be possible. A
number of additional functions are available to help out in this area, but I won't be going
into them here.

You should take the time to develop some scripts for running your backups and restores. A
naming convention so you know what database, from which server, from which date, in
what specific backup and format will be very conducive to your sanity. A common location
for backups, log, full or incremental, should be defined. Everyone responsible should be
trained in both backup and recovery and troubleshooting the same. There are many ways
of doing this, but you can find a few suggestions in Pop backs up and Pop Restores.
10 | P a g e
The real test is to run your backup mechanisms and then run a restore. Then try a different
type of restore, and another, and another. Be sure that, not only have you done due
diligence in defining how to backup the system, but that you've done the extra step of
ensuring that you can recover those backups. If you haven't practiced this and documented
the practice and then tested the document, in effect, you're not ready for a disaster.

Q6. Give a real life case where an organization has suffered due to data loss.

Ans: (Mar 20, 2009) there was a meltdown at bookmark sharing website [Link] Friday
morning. The service lost both its primary store of user data, as well as its backup. The site
has been taken offline while the team tries to reconstruct its databases, though some users
may never see their stored bookmarks again.
The failure appears to be catastrophic. The company can’t say to what extent it will be able
to restore any of its users’ data. It also says the data failure was so extensive; repairing the
loss will take "days, not hours."
[Link] posted a short note on its website shortly after 9 a.m. Pacific time, saying it was
down temporarily due to a database failure. Later Friday morning, company founder Larry
Halff issued an apology on the homepage along with the following note:
[Link] experienced every web service’s worst nightmare: data corruption and loss. For
[Link], this means that the service is offline and members’ bookmarks are unavailable,
both through the website itself and the API.
[Link] or your bookmarks will return; only that this process will take days, not hours.
[Link] also contacted Halff shortly after the outage was first reported, but he declined
to give a comment beyond what he posted on the homepage. You can get status updates
from [Link]’s Twitter account.
[Link] is a free, public service for saving links to websites. Most users rely on it as a
bookmarking storage service, or a place to save links that they may want to revisit later.
Links can be saved privately or shared publicly, so that they can be browsed by other users
looking for new destinations. Many people prefer to use bookmark sharing services like
[Link] rather than saving bookmarks locally — the main advantage being that while
your browser’s bookmarks are stored on your machine, you can access bookmarks you
share on the web from any computer with an internet connection.
[Link]’s main competitor is [Link], which is owned by Yahoo. [Link] is
preferred by many of the web’s tech elite for two reasons: The site has a robust and easy-
to-use API for accessing stored data, and it takes a snapshot when you create a bookmark,
so even if the linked site disappears, [Link] enables you to access a cached version.
Last year, [Link] mirrored its API with that of Delicious, so any web tools written for
Delicious could also be used for [Link]. The API also makes it easy to create a regular
local backup, though we suspect most people haven’t bothered to do that.

11 | P a g e

Common questions

Powered by AI

When choosing backup types for different sized systems, it is crucial to consider factors such as data change rates, system size, and recovery time objectives. Small systems may only require full backups due to manageable data sizes and low transaction volumes, providing straightforward recovery processes . Medium systems might benefit from full and log backups to balance recovery granularity with backup efficiency. For large databases, a mix of full, differential, and file/filegroup backups can optimize storage and speed, reducing time and resources needed for recovery . These considerations determine the complexity and duration of recovery processes, impacting overall business continuity and system availability.

Scheduling automates database jobs by setting specific times and frequencies for tasks to run without manual intervention. This not only ensures tasks are executed consistently but also frees up administrators to focus on other strategic tasks. For example, scheduling the job 'MCAJOB' to run every Wednesday and Friday leverages SQL Server's Agent scheduling capabilities to maintain regular execution of maintenance tasks or processes . Such automation contributes to operational efficiency by reducing the potential for human error, ensuring timely updates, and maintaining system stability with routine checks and balances.

Using an API for accessing stored data in web services, as demonstrated by Ma.gnolia, provides several advantages such as simplified data access, easy integration with other services, and enhanced flexibility for developers . Ma.gnolia's API allowed it to offer features like real-time data access and integration with other bookmarking tools like Delicious. This capability enabled users to automate data exports and synchronize bookmarks across platforms, enhancing user experience and data portability. However, Ma.gnolia's failure to ensure comprehensive backup through the API's features highlights the need for careful implementation and reliance on such systems for data management .

An effective disaster recovery plan can be tested by simulating different types of failures and practicing various restoration procedures. This testing is crucial as it not only confirms the viability of backup strategies but also ensures that recovery processes are well-documented and can be executed efficiently. The document emphasizes the importance of not just having a backup strategy but extensively practicing recovery through different types of restore scenarios . This is essential because a non-tested recovery plan could lead to prolonged downtimes or data loss during an actual disaster event.

Ma.gnolia's data loss incident underlines the critical importance of robust backup strategies and regular testing of disaster recovery procedures. Despite having a primary and backup data store, both were lost, indicating a lack of isolated or offsite backup strategies . This incident highlights the necessity of having diverse and geographically separated backup solutions to mitigate risk. Furthermore, it stresses the need for regular and comprehensive testing of restore capabilities, ensuring that backups are not only created but can also be reliably restored. Applying these lessons can fortify current practices by embedding resilience into data management processes, preventing catastrophic single-point failures.

Full backups of a database capture all data and transaction logs, providing a complete and comprehensive point-in-time recovery option. They are beneficial in offering a straightforward recovery process but can be resource-intensive, especially for large databases due to their size and time required for both backup and recovery . In contrast, file/filegroup backups allow backing up specific segments of the database, which can be advantageous in large databases where only parts of the data occasionally change. This not only reduces backup time and storage requirements but also focuses recovery efforts on the most critical data . However, they introduce complexity in the restoration process since a combination of full and filegroup backups may be needed to fully restore a database, potentially complicating disaster recovery plans.

Automated scripts are recommended for handling backups and restores in large database systems due to their ability to reduce human error, ensure consistency, and increase efficiency. For complex environments with multiple databases, scripts can systematically perform backup and restore operations with consistent parameters and scheduled frequencies . This automation allows for regular and reliable execution without manual intervention, significantly improving recovery reliability and reducing operational overhead. Furthermore, scripts can incorporate conditions and error handling, enabling quick diagnosis and remediation of issues during backup and restore processes, thus enhancing the overall stability and reliability of database operations.

Differential backups offer the advantage of faster backup times and reduced storage requirements since they only capture data modified since the last full backup. This can significantly cut down on the downtime during backup windows and optimize storage usage . However, they can complicate recovery plans as it requires restoring the full backup first, followed by the differential backup . This sequential restoration can increase recovery times and requires careful management of backup sets to ensure no differential data is lost or missed. Balancing these advantages and challenges is crucial in formulating a comprehensive disaster recovery strategy that aligns with organizational needs and resources.

Stored procedures can enhance database administration by providing a means to encapsulate complex logic or repetitive tasks into a single callable routine. This can automate tasks such as inserting records, managing accounts, and scheduling jobs. For example, in the stored procedure for creating the 'CustomerInfo' table, it ensures that CustomerID is validated before insertion . Similarly, the creation of the 'MCA_PROFILE' and associated accounts is automated through stored procedures, reducing the likelihood of error and ensuring consistency across account creation . By automating such tasks, stored procedures help in managing and organizing database operations more efficiently.

You might also like