Q. State The Basic Database Concepts
Q. State The Basic Database Concepts
Q. State The Basic Database Concepts
Ans. Data: facts that can be recorded and that have implicit meaning.
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:
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.
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
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.
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.
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.
In the relational model, relations (Tables) are used to hold information about the objects to be
represented in the database.
Q.2 State and define keys and their syntax where necessary.
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:
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:
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;
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)
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.
Syntax: R1 X R2. Where R is relation (or table you complicated clitoris fever).
Syntx: R1 U R2. Where R1 and R2 are the relations and U is the operator.
6. Set-difference (-): a binary operator. Creates a new relation with tuples that are in one relation
but not in other relation.
7. Set Intersection (∩) a binary operation. Results in a relation with tuples (rows) that are in both
the relations.
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).