SQL DBA Interview Questions 5
SQL DBA Interview Questions 5
What is a deadlock and what is a live lock? How will you go about
resolving deadlocks?
A deadlock occurs when two or more processes waits for a resource that is
acquired by or is under the control of another process. A live lock is similar to
a deadlock except the process states keeps changing. The result of such
state is that none of the process will be complete.
Blocking occurs when two or more rows are locked by one SQL connection
and a second connection to the SQL server requires a conflicting on lock on
those rows. This results in the second connection to wait until the first lock is
released.
Troubleshooting blocking:
SQL scripts can be written that constantly monitor the state of locking
and blocking on SQL Server
The common blocking scenarios must be identified and resolved.
The scripts output must be checked constantly,
The SQL profilers data must be examined regularly to detect blocking.
Differential databse backup: The database is divided into partitions that have
been modified since last complete backup. Most suitable for large databases.
The most recent differential backup contains the changes from previous
backups.
Transaction log backups: Backups only the changes logged in the transaction
log. The transaction log has all changes logged about a database. Once the
changes are accommodated on the database, the log is truncated or backed
up.
File/File Group backups: used to recover individual files or file groups. Each
filegroup can be individually backed up. This helps in recovery only the
required file or filegroup for disaster recovery.
Serializable
Repeatable read
Read committed
Read uncommitted
Table creation
{
id int primary key,
name varchar(20)
Using the SCROLL keyword while declaring a cursor allows fetching of rows in
any sequence
Example:
The active set of the cursor is stored can be accessed in any order without
the need of opening and closing the cursor. The Scroll cursors can be set for
select and function cursors but not insert or update statements.
When a cursor is declared as DYNAMIC, the cursor reflects all changes made
to the base tables as the cursor is scrolled around.
FOR select_statement
Database files are used for mapping the database over some operating
system files. Data and log information are separate. SQL server database has
three types of database files:
SQL Server consists of a set of various components which fulfill data storage
and data analysis needs for enterprise applications. Database architecture:
All the data is stored in databases which is organized into logical components
visible to the end users. It’s only the administrator who needs to actually deal
with the physical storage aspect of the databases, whereas users only deal
with database tables.
Every SQL Server instance has primarily 4 system database i.e. master,
model, tempdb and msdb. All other databases are user created databases as
per their needs and requirements.