Professional Documents
Culture Documents
Database:
A database is a collection of information that is organized. So that it can
easily be accessed, managed, and updated.
DBMS:
DBMS stands for Database Management System. It is a collection of
programs that enables user to create and maintain a database
Advantages of DBMS
• Redundancy is controlled.
• Providing multiple user interfaces.
• Providing backup and recovery
• Unauthorized access is restricted.
• Enforcing integrity constraints.
• Data: Known facts that can be recorded and have an implicit meaning.
• The 3-Tier architecture contains another layer between the client and
server.
• Introduction of 3-tier architecture is for the ease of the users as it
provides the GUI, which, make the system secure and much more
accessible.
• In this architecture, the application on the client-end interacts with an
application on the server which further communicates with the
database system.
How do you communicate with an RDBMS?
Relation schemas that do not meet the properties are decomposed into
smaller relation schemas that could meet desirable properties.
Different levels of abstraction in the
DBMS?
• Physical Level: This is the lowest level of the data abstraction which
states how the data is stored in the database.
• Logical Level: This is the next level of the data abstraction which
states the type of the data and the relationship among the data that is
stored in the database.
• View Level: This is the highest level in the data abstraction which
shows/states only a part of the database.
Integrity rules exist in the DBMS
• Entity Integrity: This states a very important rule that value of a
Primary key can never have a NULL value.
• Referential Integrity: This rule is related to the Foreign key which
states that either the value of a Foreign key is a NULL value or it
should be the primary key of any other relation.
Different type of relationships in the
DBMS?
• One-to-One: This basically states that there should be a one-to-one
relationship between the tables i.e. there should be one record in both the
tables. Example: Among a married couple, both wife and husband can
have only one spouse.
• One-to-Many: This states that there can be many relationships for one
i.e. a primary key table hold only one record which can have many, one
or none records in the related table. Example: A Mother can have many
children.
• Many-to-Many: This states that both the tables can be related to many
other tables. Example: One can have many siblings and so do they have.
E-R model in the DBMS
• E-R model is known as an Entity-Relationship model in the DBMS
which is based on the concept of the Entities and the relationship that
exists among these entities.
Functional dependency in the DBMS
• This is basically a constraint which is useful in describing the
relationship among the different attributes in a relation.
• Its helps in preventing data redundancy and get to know about bad
design.
• Given a relation R,a set of attributes X in R said to functionally
determine another set of attributes Y, also in R,(Written XY) if, and
only if, each X value is associated with precisely one Y value;R is then
said to satisfy the functional dependency XY
What is SQL?
• SQL is Structured Query Language designed for inserting and
modifying in a relational database system.
What is the concept of sub-query in terms
of SQL?
• Sub-query is basically the query which is included inside some other
query and can also be called as an inner query which is found inside
the outer query.
Differences between DROP, TRUNCATE
and DELETE commands?
• DROP and TRUNCATE commands are the DDL commands which
are used to delete tables from the database and once the table gets
deleted, all the privileges and indexes that are related to the table also
get deleted. These 2 operations cannot be rolled back and so should be
used only when necessary.
• DELETE command, on the other hand, is a DML Command which is
also used to delete rows from the table and this can be rolled back.
Difference between UNION and UNION
ALL?
• UNION and UNION ALL are used to join the data from 2 or more
tables but UNION removes duplicate rows and picks the rows which
are distinct after combining the data from the tables whereas UNION
ALL does not remove the duplicate rows, it just picks all the data from
the tables.
join in the SQL
• A Join is one of the SQL statements which is used to join the data or
the rows from 2 or more tables on the basis of a common field/column
among the.m
different types of joins in SQL?
• Inner Join: This type of join is used to fetch the data among the tables
which are common in both the tables.
• Left Join: This returns all the rows from the table which is on the left
side of the join but only the matching rows from the table which is on
the right side of the join.
• Right Join: This returns all the rows from the table which is on the
right side of the join but only the matching rows from the table which
is on the left side of the join.
• Full Join: This returns the rows from all the tables on which the join
condition has put and the rows which do not match hold null values.
Different types of languages that are
available in the DBMS?
• DDL: DDL is Data Definition Language which is used to define the
database and schema structure by using some set of SQL Queries
like CREATE, ALTER, TRUNCATE, DROP and RENAME.
• DCL: DCL is Data Control Language which is used to control the
access of the users inside the database by using some set of SQL
Queries like GRANT and REVOKE.
• DML: DML is Data Manipulation Language which is used to do
some manipulations in the database like Insertion, Deletion, etc. by
using some set of SQL Queries
like SELECT, INSERT, DELETE and UPDATE.
What is a view in SQL? How to create one
• A view is a virtual table based on the result-set of an SQL statement.
We can create using create view syntax.
What is the purpose of SQL?
• SQL stands for Structured Query Language whose main purpose is
to interact with the relational databases in the form of inserting and
updating/modifying the data in the database.
uses of view?
1. Views can represent a subset of the data contained in a table;
consequently, a view can limit the degree of exposure of the
underlying tables to the outer world: a given user may have
permission to query the view, while denied access to the rest of the
base table.
2. Views can join and simplify multiple tables into a single virtual table
3. Views can act as aggregated tables, where the database engine
aggregates data (sum, average etc.) and presents the calculated
results as part of the data.
4. Views can hide the complexity of data; for example a view could
appear as Sales2000 or Sales2001, transparently partitioning the actual
underlying table.
5. Views take very little space to store; the database contains only the
definition of a view, not a copy of all the data which it presents.
6. Depending on the SQL engine used, views can provide extra security
DROP, TRUNCATE and DELETE
commands?
Pattern matching in SQL?
You can perform pattern matching in SQL by using the LIKE operator.
With the LIKE operator, you can use the following symbols:
• %(Percentage sign) – To match zero or more characters.
• _ (Underscore) –To match exactly one character.
• Example:
• SELECT * FROM Customers WHERE CustomerName LIKE ‘s%’
• SELECT * FROM Customers WHERE CustomerName like ‘xyz_’
Trigger
• A Trigger is a code that associated with insert, update or delete
operations. The code is executed automatically whenever the
associated query is executed on a table. Triggers can be useful to
maintain integrity in database.
Stored procedure?
• A stored procedure is like a function that contains a set of operations
compiled together. It contains a set of operations that are commonly
used in an application to do some common database tasks.
Difference between Trigger and Stored
Procedure?
• Unlike Stored Procedures, Triggers cannot be called directly. They can
only be associated with queries.
Four applications for triggers.
(1)Providing default values,
(2) Enforcing data constraints,
(3) Updating views and
(4) Enforcing referential integrity
Advantages of using stored procedures?
The advantages of stored procedures are
(1) greater security,
(2) decreased network traffic,
(3) the fact that SQL can be optimized and
(4) code sharing which leads to less work, standardized processing, and
specialization among developers.
What is a transaction?
• A Database Transaction is a set of database operations that must be
treated as whole, means either all operations are executed or none of
them.
• Shared lock: Shared lock is required for reading a data item. In the
shared lock, many transactions may hold a lock on the same data item.
When more than one transaction is allowed to read the data items then
that is known as the shared lock.
• Exclusive lock: When any transaction is about to perform the write
operation, then the lock on the data item is an exclusive lock. Because,
if we allow more than one transaction then that will lead to the
inconsistency in the database.
Purpose of normalization in DBMS?
Normalization is the process of analyzing the relational schemas which
are based on their respective functional dependencies and the primary
keys in order to fulfill certain properties.
The properties include:
• To minimize the redundancy of the data.
• To minimize the Insert, Delete and Update Anomalies.
Anomalies in DBMS
• There are three types of anomalies that occur when the database is not
normalized. These are – Insertion, update and deletion anomaly.
• Example: Suppose a manufacturing company stores the employee
details in a table named employee that has four attributes: emp_id for
storing employee’s id, emp_name for storing employee’s name,
emp_address for storing employee’s address and emp_dept for storing
the department details in which the employee works. At some point of
time the table looks like this:
The Below table is not normalized. We will see the
problems that we face when a table is not normalized.
• Update anomaly: In the above table we have two rows for employee
Rick as he belongs to two departments of the company. If we want to
update the address of Rick then we have to update the same in two
rows or the data will become inconsistent. If somehow, the correct
address gets updated in one department but not in other then as per the
database, Rick would be having two different addresses, which is not
correct and would lead to inconsistent data.
• Insert anomaly: Suppose a new employee joins the company, who is
under training and currently not assigned to any department then we
would not be able to insert the data into the table if emp_dept field
doesn’t allo
• Delete anomaly: Suppose, if at a point of time the company closes the
department D890 then deleting the rows that are having emp_dept as
D890 would also delete the information of employee Maggie since she
is assigned only to this department.
To overcome these anomalies we need to normalize the data
Commonly used normal forms are:
• First Normal Form(1NF)
• Second Normal Form(2NF)
• Third Normal Form(3NF)
• Boyce & Codd Normal Form(BCNF)
1NF?