Professional Documents
Culture Documents
For example: The college Database organizes the data about the admin, staff,
students and faculty etc.
Using the database, you can easily retrieve, insert, and delete the information.
The collection of database and DBMS software together is known as a database system.
Characteristics of DBMS
o Redundancy control [Data redundancy occurs when the same piece of data is stored
in two or more separate places]
o Restriction for unauthorized access
o Provides multiple user interfaces [It provides different types of user interfaces like
graphical user interfaces, application program interfaces]
o Provides backup and recovery
o Enforces integrity constraints
o Ensure data consistency
o Easy accessibility
o Easy data extraction and data processing due to the use of queries
Disadvantages of DBMS
o Cost of Hardware and Software: It requires a high speed of data processor and large
memory size to run DBMS software.
o Size: It occupies a large space of disks and large memory to run them efficiently.
o Complexity: Database system creates additional complexity and requirements.
o Higher impact of failure: Failure is highly impacted the database because in most of
the organization, all the data stored in a single database and if the database is damaged
due to electric failure or database corruption then the data may be lost forever.
Data Integrity
o There are the following categories of data integrity exist with each RDBMS:
o User-defined integrity: It enforces some specific business rules that are defined by
users. These rules are different from entity, domain or referential integrity.
2) In DBMS, data is generally stored In RDBMS, the tables have an identifier called
in either a hierarchical form or a primary key and the data values are stored in
navigational form. the form of tables.
4) DBMS does not apply any RDBMS defines the integrity constraint for
security with regards to data the purpose of ACID (Atomocity, Consistency,
manipulation. Isolation and Durability) property.
5) DBMS uses file system to store in RDBMS, data values are stored in the form
data, so there will be no relation of tables, so a relationship between these data
between the tables. values will be stored in the form of a table as
well.
9) Examples of DBMS are file Example of RDBMS are mysql, postgre, sql
systems, xml etc. server, oracle etc.
It doesn’t provide backup and It provides backup and recovery of data even
3. recovery of data if it is lost. if it is lost.
There is less data consistency in There is more data consistency because of the
5. file system. process of normalization.
File systems provide less security DBMS has more security mechanisms as
7. in comparison to DBMS. compared to file system.
All modern database management systems like SQL, MS SQL Server, IBM DB2, ORACLE,
My-SQL and Microsoft Access are based on RDBMS.
How it works
Due to a collection of organized set of tables, data can be accessed easily in RDBMS.
NULL Values
The NULL value of the table specifies that the field has been left blank during record
creation. It is totally different from the value filled with zero or a field that contains space.
1-Tier Architecture
o In this architecture, the database is directly available to the user. It means the user can
directly sit on the DBMS and uses it.
o Any changes done here will directly be done on the database itself. It doesn't provide
a handy tool for end users.
o The 1-Tier architecture is used for development of the local application, where
programmers can directly communicate with the database for the quick response.
o 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.
11) What do you understand by Data Model?
o The Data model is specified as a collection of conceptual tools for describing data,
data relationships, data semantics and constraints. These models are used to describe
the relationship between the entities and their attributes.
Data Independence
Data independence refers characteristic of being able to modify the schema at one level of the
database system without altering the schema at the next higher level.
o Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual
view.
o Physical data independence can be defined as the capacity to change the internal
schema without having to change the conceptual schema.
o If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
o Physical data independence is used to separate conceptual levels from the internal
levels.
Database Language
o DDL stands for Data Definition Language. It is used to define database structure or
pattern.
o It is used to create schema, tables, indexes, constraints, etc. in the database.
o Using the DDL statements, you can create the skeleton of the database.
o Data definition language is used to store the information of metadata like the number
of tables and schemas, their names, indexes, columns in each table, constraints, etc.
These commands are used to update the database schema that's why they come under Data
definition language.
DML stands for Data Manipulation Language. It is used for accessing and manipulating data
in a database. It handles user requests.
7.3M
131
Difference between JDK, JRE, and JVM
o DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
o The DCL execution is transactional. It also has rollback parameters.
(But in Oracle database, the execution of data control language does not have the
feature of rolling back.)
There are the following operations which have the authorization of Revoke:
TCL is used to run the changes made by the DML statement. TCL can be grouped into a
logical transaction.
o ACID properties are some basic rules, which has to be satisfied by every transaction
to preserve the integrity. These properties and rules are:
o DURABILITY: This property ensures that once the transaction is committed it will
be stored in the non-volatile memory and system crash can also not affect it anymore.
o E-R model is a short name for the Entity-Relationship model. This model is based on
the real world. It contains necessary objects (known as entities) and the relationship
among these objects. Here the primary objects are the entity, attribute of that entity,
relationship set, an attribute of that relationship set can be mapped in the form of E-R
diagram.
o For example, Suppose we design a school database. In this database, the student will
be an entity with attributes like address, name, id, age, etc. The address can be another
entity with attributes like city, street name, pin code, etc and there will be a
relationship between them.
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be
represented as rectangles.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain
any key attribute of its own. The weak entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.
For example, id, age, contact number, name, etc. can be attributes of a student
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a
primary key. The key attribute is represented by an ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The
composite attribute is represented by an ellipse, and those ellipses are connected with an
ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued
attribute. The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be
represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute
like Date of birth.
An entity type is specified as a collection of entities, having the same attributes. Entity type
typically corresponds to one or several related tables in the database. A characteristic or trait
which defines or uniquely identifies the entity is called entity type.
For example, a student has student_id, department, and course as its characteristics.
The entity set specifies the collection of all entities of a particular entity type in the database.
An entity set is known as the set of all the entities which share the same properties.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used
to represent the relationship.
One-to-one
In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and an
entity in E2 is associated with at most one entity in E1.
One-to-many
In one-to-many mapping, an entity in E1 is associated with any number of entities in E2, and
an entity in E2 is associated with at most one entity in E1.
Many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one entity in E2, and an
entity in E2 is associated with any number of entities in E1.
Many-to-many
Relational model can represent as a table with columns and rows. Each row is known as a
tuple. Each table of the column has a name or attribute.
Attribute: It contains the name of a column in a particular table. Each attribute Ai must have
a domain, dom(Ai)
Relational instance: In the relational database system, the relational instance is represented
by a finite set of tuples. Relation instances do not have duplicate tuples.
Relational schema: A relational schema contains the name of the relation and name of all
columns or attributes.
Relational key: In the relational key, each row has one or more attributes. It can identify the
row in the relation uniquely.
) Normalization
o Normalization is the process of organizing the data in the database.
o Normalization is used to minimize the redundancy from a relation or set of relations.
It is also used to eliminate the undesirable characteristics like Insertion, Update and
Deletion Anomalies.
o Normalization divides the larger table into the smaller table and links them using
relationship.
o The normal form is used to reduce redundancy from the database table.
1NF is the First Normal Form. It is the simplest type of normalization that you can
implement in a database. The primary objectives of 1NF are to:
2NF is the Second Normal Form. A table is said to be 2NF if it follows the following
conditions:
o The table is in 1NF, i.e., firstly it is necessary that the table should follow the rules of
1NF.
o Every non-prime attribute is fully functionally dependent on the primary key, i.e.,
every non-key attribute should be dependent on the primary key in such a way that if
any key element is deleted, then even the non_key element will still be saved in the
database.
3NF stands for Third Normal Form. A database is called in 3NF if it satisfies the following
conditions:
BCMF stands for Boyce-Codd Normal Form. It is an advanced version of 3NF, so it is also
referred to as 3.5NF. BCNF is stricter than 3NF.
o It is in 3NF.
o For every functional dependency X->Y, X should be the super key of the table. It
merely means that X cannot be a non-prime attribute if Y is a prime attribute.
Keys
PRIMARY KEY
• It is a set of one or more attributes of the table that uniquely identify a record in
database table
• It cannot accept null values, duplicate values
• Only one candidate key can be primary key
• Ex: In Student Table out of many attributes the registration number of the
student can be considered as the primary key
UNIQUE KEY
• There is a similarity between the Primary Key and the Unique Key
• It is a set of one or more attributes of the table that uniquely identify a record in
database table
• It can accept null values
• But it cannot accept duplicate values
A LT E R N AT E K E Y ( S E C O N D A RY K E Y )
• It can work as a primary key i.e., (Unique, Not Null values, No duplicate)
• Basically it is a candidate key that currently is not primary key
CANDIDATE KEY
• It is a set of one or more attributes that can identify a record uniquely in table
• There are multiple candidate keys in a table
• Each candidate key can work as Primary Key
• Ex: Roll No., Registration No. both represent the same form
• Candidate Key => Alternate Key => Primary Key
SUPER KEY
• It is the superset of Primary Key, Candidate Key, Unique Key and Alternate Key
• It is a set of one or more than one keys that can be used to identify a record
uniquely in a table
COMPOSITE KEY
FOREIGN KEY
DBMS Interfaces
Some of the user-friendly interfaces provided by a DBMS include the following:
1. Menu-Based Interfaces for Browsing – These interfaces present the user with
lists of options called menus that lead the user through the formulation of a
request. These are often used in browsing interfaces which allow user to look
through the contents of a database in an exploratory and unstructured
manner.
2. Forms-Based Interfaces – These interface displays a form to each user. Users
can fill out all of the form entries to insert new data. Forms are usually
designed and programmed for users as interfaces to carry out transactions.
3. Graphical User Interfaces – A GUI typically displays a schema to the user in
diagrammatic form. It can utilize both menus and forms. The user can specify a
query by manipulating the diagram.
4. Natural Language Interfaces - These interfaces accept requests written in
English or some other language and attempt to understand them. A natural
language interface usually has its own schema, and refers to the words in its
schema to interpret the request. It the interpretation is successful, the
interface generates a high-level query corresponding to the natural language
request and submits it to the DBMS for processing.
5. Speech Input and Output – Limited use of speech as an input query and
speech as an answer to a question or result of a request is common. The
speech input is detected using a library of predefined words and is used to set
up the parameters that are supplied to the queries.
6. Interfaces for Parametric Users – a small number of abbreviated commands is
included, with the goal of minimizing the number of keystrokes required for
each request.
7. Interfaces for the Database Administrator (DBA) – Most database systems
contain privileged commands that can be used only the DBA’s staff. These
include commands for creating accounts, setting system parameters, granting
account authorization, changing a schema and reorganizing the storage
structures of a database.
Relational Algebra
Relational algebra is a procedural query language. It gives a step by step process to
obtain the result of the query. It uses operators to perform queries.
1. Select Operation:
1. Notation: σ p(r)
p is used as a propositional logic formula which may use connectors like: AND OR and
NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
Input:
1. σ BRANCH_NAME="perryride" (LOAN)
Output:
2. Project Operation:
o This operation shows the list of those attributes that we wish to appear in the result.
Rest of the attributes are eliminated from the table.
o It is denoted by ∏.
Where
Input:
Output:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
3. Union Operation:
o Suppose there are two tuples R and S. The union operation contains all the tuples that
are either in R or S or both in R & S.
o It eliminates the duplicate tuples. It is denoted by ∪.
1. Notation: R ∪ S
Example:
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
Input:
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
4. Set Intersection:
o Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in both R & S.
o It is denoted by intersection ∩.
1. Notation: R ∩ S
Input:
Output:
CUSTOMER_NAME
Smith
Jones
5. Set Difference:
o Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in R but not in S.
o It is denoted by intersection minus (-).
1. Notation: R - S
Example: Using the above DEPOSITOR table and BORROW table
Input:
Output:
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
6. Cartesian product
o The Cartesian product is used to combine each row in one table with each row in the
other table. It is also known as a cross product.
o It is denoted by X.
1. Notation: E X D
Example:
EMPLOYEE
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
Input:
1. EMPLOYEE X DEPARTMENT
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
Output:
7. Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ).
Example: We can use the rename operator to rename STUDENT relation to STUDENT1.
1. ρ(STUDENT1, STUDENT)
Join Operations:
A Join operation combines related tuples from different relations, if and only if a given join
condition is satisfied. It is denoted by ⋈.
Example:
EMPLOYEE
EMP_CODE SALARY
101 50000
102 30000
103 25000
EMP_CODE EMP_NAME
101 Stephan
102 Jack
103 Harry
SALARY
Result:
7.5M
134
Difference between JDK, JRE, and JVM
o A natural join is the set of tuples of all combinations in R and S that are equal on their
common attribute names.
o It is denoted by ⋈.
Example: Let's use the above EMPLOYEE table and SALARY table:
Input:
Output:
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
2. Outer Join:
The outer join operation is an extension of the join operation. It is used to deal with missing
information.
Example:
EMPLOYEE
FACT_WORKERS
Input:
1. (EMPLOYEE ⋈ FACT_WORKERS)
Output:
Input:
1. EMPLOYEE ⟕ FACT_WORKERS
o Right outer join contains the set of tuples of all combinations in R and S that are equal
on their common attribute names.
o In right outer join, tuples in S have no matching tuples in R.
o It is denoted by ⟖.
Input:
1. EMPLOYEE ⟖ FACT_WORKERS
Output:
o Full outer join is like a left or right join except that it contains all rows from both
tables.
o In full outer join, tuples in R that have no matching tuples in S and tuples in S that
have no matching tuples in R in their common attribute name.
o It is denoted by ⟗.
Input:
1. EMPLOYEE ⟗ FACT_WORKERS
Output:
3. Equi join:
It is also known as an inner join. It is the most common join. It is based on matched data as
per the equality condition. The equi join uses the comparison operator(=).
Example:
CUSTOMER RELATION
CLASS_ID NAME
1 John
2 Harry
3 Jackson
PRODUCT
PRODUCT_ID CITY
1 Delhi
2 Mumbai
3 Noida
Input:
1. CUSTOMER ⋈ PRODUCT
Output:
1 John 1 Delhi
2 Harry 2 Mumbai
3 Harry 3 Noida
Integrity Constraints
o Integrity constraints are a set of rules. It is used to maintain the quality of information.
o Integrity constraints ensure that the data insertion, updating, and other processes have
to be performed in such a way that data integrity is not affected.
o Thus, integrity constraint is used to guard against accidental damage to the database.
1. Domain constraints
o Domain constraints can be defined as the definition of a valid set of values for an
attribute.
o The data type of domain includes string, character, integer, time, date, currency, etc.
The value of the attribute must be available in the corresponding domain.
Example:
o The entity integrity constraint states that primary key value can't be null.
o This is because the primary key value is used to identify individual rows in relation
and if the primary key has a null value, then we can't identify those rows.
o A table can contain a null value other than the primary key field.
Example:
Example:
4. Key constraints
o Keys are the entity set that is used to identify an entity within its entity set uniquely.
o An entity set can have multiple keys, but out of which one key will be the primary
key. A primary key can contain a unique and null value in the relational table.
Example:
SQL
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures the
accuracy and reliability of the data in the table. If there is any violation between the
constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a column,
and table level constraints apply to the whole table.
SQL (Structured Query Language) is used to perform operations on the records stored in the
database, such as updating records, inserting records, deleting records, creating and
modifying database tables, views, etc.
Why SQL?
o The basic use of SQL for data professionals and SQL users is to insert, update, and
delete the data from the relational database.
o SQL allows the data professionals and users to retrieve the data from the relational
database management systems.
o It also helps them to describe the structured data.
o It allows SQL users to create, drop, and manipulate the database and its tables.
o It also helps in creating the view, stored procedure, and functions in the relational
database.
o It allows you to define the data and modify that stored data in the relational database.
o It also allows SQL users to set the permissions or constraints on table columns, views,
and stored procedures.
o Advantages of SQL
1. No programming needed
o SQL does not require a large number of coding lines for managing the database
systems. We can easily access and maintain the database by using simple SQL
syntactical rules. These simple rules make the SQL user-friendly.
o A large amount of data is accessed quickly and efficiently from the database by using
SQL queries. Insertion, deletion, and updation operations on data are also performed
in less time.
3. Standardized Language
o SQL follows the long-established standards of ISO and ANSI, which offer a uniform
platform across the globe to all its users.
4. Portability
o The structured query language can be easily used in desktop computers, laptops,
tablets, and even smartphones. It can also be used with other applications according to
the user's requirements.
5. Interactive language
o We can easily learn and understand the SQL language. We can also use this language
for communicating with the database because it is a simple query language. This
language is also used for receiving the answers to complex queries in a few seconds.
o The SQL language also helps in making the multiple views of the database structure
for the different database users.
Disadvantages of SQL
o With the advantages of SQL, it also has some disadvantages, which are as follows:
1. Cost
o The operation cost of some SQL versions is high. That's why some programmers
cannot use the Structured Query Language.
2. Interface is Complex
o Another big disadvantage is that the interface of Structured query language is
difficult, which makes it difficult for SQL users to use and manage it.
o The business rules are hidden. So, the data professionals and users who are using this
query language cannot have full database control.
SQL Statement
SQL statements tell the database what operation you want to perform on the structured data
and what information you would like to access from the database.
Each SQL statement begins with any of the SQL keywords and ends with the semicolon (;).
The semicolon is used in the SQL for separating the multiple Sql statements which are going
to execute in the same call. In this SQL tutorial, we will use the semicolon (;) at the end of
each SQL query or statement.
1. Select Statement
2. Update Statement
3. Delete Statement
4. Create Table Statement
5. Alter Table Statement
6. Drop Table Statement
7. Create Database Statement
8. Drop Database Statement
9. Insert Into Statement
10. Truncate Table Statement
11. Describe Statement
12. Distinct Clause
13. Commit Statement
14. Rollback Statement
15. Create Index Statement
16. Drop Index Statement
17. Use Statement
Let's discuss each statement in short one by one with syntax and one example:
1. SELECT Statement
This SQL statement reads the data from the SQL database and shows it as the output to the
database user.
This example shows the Emp_ID, First_Name, Last_Name, Salary, and City of those
employees from the Employee_details table whose Salary is 100000. The output shows all
the specified details according to the ascending alphabetical order of Last_Name.
3. UPDATE Statement
This SQL statement changes or modifies the stored data in the SQL database.
1. UPDATE table_name
2. SET column_name1 = new_value_1, column_name2 = new_value_2, ...., column_na
meN = new_value_N
3. [ WHERE CONDITION ];
1. UPDATE Employee_details
2. SET Salary = 100000
3. WHERE Emp_ID = 10;
This example changes the Salary of those employees of the Employee_details table
whose Emp_ID is 10 in the table.
3. DELETE Statement
This SQL statement deletes the stored data from the SQL database.
This example deletes the record of those employees from the Employee_details table
whose First_Name is Sumit in the table.
This SQL statement creates the new table in the SQL database.
This example creates the table Employee_details with five columns or fields in the SQL
database. The fields in the table are Emp_Id, First_Name, Last_Name, Salary, and City.
The Emp_Id column in the table acts as a primary key, which means that the Emp_Id
column cannot contain duplicate values and null values.
This SQL statement adds, deletes, and modifies the columns of the table in the SQL database.
The above SQL alter statement adds the column with its datatype in the existing database
table.
The above 'SQL alter statement' renames the old column name to the new column name of
the existing database table.
The above SQL alter statement deletes the column of the existing database table.
This example adds the new field whose name is Designation with size 18 in
the Employee_details table of the SQL database.
This SQL statement deletes or removes the table and the structure, views, permissions, and
triggers associated with that table.
This example drops the Employee_details table if it exists in the SQL database. This
removes the complete information if available in the table.
This SQL statement creates the new database in the database management system.
This SQL statement deletes the existing database with all the data tables and views from the
database management system.
The above example deletes the company database from the system.
This SQL statement inserts the data or records in the existing table of the SQL database. This
statement can easily insert single and multiple records in a single query statement.
This example inserts 101 in the first column, Akhil in the second column, Sharma in the
third column, 40000 in the fourth column, and Bangalore in the last column of the
table Employee_details.
This example inserts the records of three employees in the Employee_details table in the
single query statement.
This SQL statement deletes all the stored records from the table of the SQL database.
This example deletes the record of all employees from the Employee_details table of the
database.
This SQL statement tells something about the specified table or view in the query.
1. DESCRIBE Employee_details;
This example explains the structure and other details about the Employee_details table.
This SQL statement shows the distinct values from the specified columns of the database
table. This statement is used with the SELECT keyword.
This example shows the distinct values of the City and Salary column from
the Employee_details table.
This SQL statement saves the changes permanently, which are done in the transaction of the
SQL database.
1. COMMIT
This example deletes the records of those employees whose Salary is 30000 and then saves
the changes permanently in the database.
This SQL statement undo the transactions and operations which are not yet saved to the SQL
database.
1. ROLLBACK
This example deletes the records of those employees whose City is Mumbai and then undo
the changes in the database.
This SQL statement deletes the existing index of the SQL database table.
This example deletes the index idx_First_Name from the SQL database.
This SQL statement selects the existing SQL database. Before performing the operations on
the database table, you have to select the database from the multiple existing databases.
1. USE database_name;
1. USE Company;