Q. State The Basic Database Concepts

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Chapter 1

Q. State the basic database concepts.

Ans. Data: facts that can be recorded and that have implicit meaning.

Database: collection of related data.

DBMS: collection of programs enabling users to create and maintain a database.

DBMS process: defining, constructing, manipulating, and sharing.

DBMS Characteristics:

 Self-describing nature: Database contains a complete description of the database structure and
constraints in a catalog.
 Separation between programs and data: By difference of traditional file system, DBMS do not
require that any changes to the structure of a file may require changing all programs that access
that file such changes in most cases.
 Multiple views of the data: A database typically has many users, each of whom require a
different view of the database.
 Sharing of data and multiuser transaction processing: must allow multiple users to access the
database at the same time.

Advantages of DBMS:

 Controlling Redundancy (Duplication)


 Restricting Unauthorized Access
 Providing Permanent Storage, Backup and Recovery, Multiple User Interfaces
 Representing Complex Relationships among Data

ACID Properties: in order to ensure accuracy, completeness, and data integrity. A transaction in a
database system must maintain Atomicity, Consistency, Isolation, and Durability commonly known as
ACID properties.

 Atomicity − either all of its operations are executed or none.


 Consistency − the database must remain in a consistent (stable) state after any transaction.
 Durability − the database should be durable enough to hold all its latest updates even if the
system fails or restarts.
 Isolation − the property of isolation states that all the transactions will be carried out and
executed as if it is the only transaction in the system. No transaction will affect the existence of
any other transaction.
Chapter 2
Q.1 State the basic DBMS Architectural concepts.

Ans. DBMS design depends on its Architecture. Architecture of a DBMS can be either single tier or multi-
tier

 1-tier: here DBMS is the only entity where the user directly shits on the DBMS and uses it.
Database designers and programmers prefer to use single-tier architecture.
 2-tier: here DBMS is accessed by an application.
 3-tier: consists of presentation layer at the front, application layer in the middle and database
layer at the end

Data-Model: collection of concepts describing database structure.

Categories of Data-Model:

 High-level/conceptual: provide concepts that are close to the way many users perceive data.
 Low-level/physical provide concept of how data is stored on the computer storage media.

Entity: represents a real-world object. E.g. employee.

Attribute: represents a property that further describes an entity. E.g. employee’s name or salary.

Relationship: represents an association among the entities. E.g. employee and a project.

Schemas: description of a database. Specified during database design. Not expected to change
frequently.

Instance: set of memory structures that manage database files.

State: The data in the database at a particular moment in time. E.g. in new database the database state
is empty state with no data.

Three schemas architecture: Its goal is to separate the user applications from the physical database.

 Internal level schema: describes


the physical storage structure of
the database.
 Conceptual level schema:
describes the structure of the
whole database. Hides the
details of physical storage
structures
 External level schema: describes
the part of the database that a
particular user group is
interested in and hides the rest.
Chapter 3
Q.1 State the relational model and its basic concepts.

Ans. Introduced by E. F. Codd in 1970 based on the mathematical concept of a relation.

In the relational model, relations (Tables) are used to hold information about the objects to be
represented in the database.

Relation: a table with columns and rows.

 Unary relation: relation with one attribute (column).


 Binary relation: two attributes (column).
 Ternary: three attributes (column).
 N (number)-ary: more than three Attributes (column).

Attribute: a named column of a relation (table).

Domain: set of values allowed in an attribute (column).

Tuple: a row of a relation (table).

Degree: number of attributes (columns) it contains.

Cardinality: number of tuples (rows) it contains.

Q.2 State and define keys and their syntax where necessary.

Super Key: any combination of fields. Super set of candidate key.

Candidate Key: a single field or the least combination of fields. Subset of super key

Primary Key: a candidate key that is most suitable to be the main reference key for the table.

Properties and syntax: Unique values, Must never be null, uniquely identify each record in the
table.

Syntax:

CREATE TABLE Persons (


ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
Foreign Key: a unique key from one table and a field in another. Where the first table has a relationship
to the second.

Syntax: suppose we have a table named “Persons” containing person name age and personid. Now we
create another table named “Orders” as a foreign key:

CREATE TABLE Orders (


OrderID int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int FOREIGN KEY REFERENCES Persons(PersonID)
);
Secondary/alternate key: One is selected as the primary key. Those not selected are known as secondary
keys or alternative keys.

Unique Key Constraints:

Composite Key: A key composed of one or more column.

Chapter Joins
Q.1 describe join and types of joins with syntax.

Ans. Join is used to fetch data from two or more tables, as single set of data.

1. Inner Joins (Simple Join): returns all rows from multiple tables where condition is met.
Syntax:
SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;
2. Outer Joins: specified into three types.
a. Left Outer Join (Left Join): returns all rows from the left table and only those rows from
the right table where the condition is met.
Syntax:
SELECT columns
FROM table1
LEFT [OUTER] JOIN table2 ON table1.column = table2.column;
b. Right Outer Join (Right Join): returns all rows from the right table and only those rows
from the left table where the condition is met.
Syntax:
SELECT columns
FROM table1
RIGHT [OUTER] JOIN table2 ON table1.column = table2.column;

c. Full Outer Join (Full Join): returns all rows from the left table and right table. It places
NULL where the condition is not met.
Syntax:

SELECT columns
FROM table1
FULL [OUTER] JOIN table2 ON table1.column = table2.column;
3. Equijoins: It uses a comparison operator WHERE clause to refer equality. Same as INNER JOIN.
Syntax:
SELECT column_list
FROM table1, table2....
WHERE table1.column_name = table2.column_name;
4. Cross Joins (Cartesian Products): returns all rows from first table and the second table.

Syntax:

SELECT *
FROM table1
CROSS JOIN table2;

Chapter Relational Algebra


Q.1 Describe Relational Algebra and its basic operators.

Relational algebra is a procedural language. Provides operators which perform operations on existing
relation to derive results relations (Means tables :p). It results always distinct tuple. Operator
can be either unary or binary.

They accept relations as their input and yield relations as their output.

Basic Operations:

1. Select (σ): a unary relational operation. Pulls the subset of rows of the table that satisfies the
conditions.

Syntax: σ p (r), here the σ is select operation p is condition and (r) is relation (table
name)

Example: “σ STD_NAME = “James” (STUDENT)”.

2. Project (∏): a unary operator. Similar to select operation above.

Syntax: ∏a1, a2, a3 (r).

Example: ∏std_name, address, course (STUDENT).

3. Rename (ρ): a unary operator used to rename the tables and columns of a relation.

Syntax: ρ R(E). Where ρ is the rename operator, E is the existing name, and R is the new
name.

Example: ρ STUDENT (STD_TABLE)


4. Cartesian product (X): a binary operator. It combines the tuples of two relations into one
relation.

Syntax: R1 X R2. Where R is relation (or table you complicated clitoris fever).

5. Union (U): a binary operator. Combines the tuples of two relations.

Syntx: R1 U R2. Where R1 and R2 are the relations and U is the operator.

Example: DESIGN_EMPLOYEE U TESTING_EMPLOYEE

6. Set-difference (-): a binary operator. Creates a new relation with tuples that are in one relation
but not in other relation.

Syntax: R1 – R2. Where R1 and R2 are the relations.

7. Set Intersection (∩) a binary operation. Results in a relation with tuples (rows) that are in both
the relations.

Syntax: R∩S. Where R and S are the relations.

Chapter Query optimization


Q.1 Describe query optimization and its importance.

Ans. QO: process of choosing most efficient way of executing a SQL statement.

Importance: The goal of query optimization is to reduce the system resources required to fulfill a query,
and ultimately provide the user with the correct result set faster.

First, it provides the user with faster results, which makes the application seem faster to the user.

Secondly, it allows the system to service more queries in the same amount of time, because each
request takes less time than unoptimized queries.

Thirdly, query optimization ultimately reduces the amount of wear on the hardware (e.g. disk drives),
and allows the server to run more efficiently (e.g. lower power consumption, less memory usage).

You might also like