0% found this document useful (0 votes)
5 views

Ch-11 Relational Databases

The document provides an overview of database concepts, including the definition and importance of databases, the role of Database Management Systems (DBMS), and the advantages of using a DBMS. It explains data abstraction, data models, and the relational database model, detailing key components such as keys, referential integrity, and SQL commands. Additionally, it introduces MySQL as an open-source RDBMS and outlines SQL's various commands for managing databases.

Uploaded by

Sanjay Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Ch-11 Relational Databases

The document provides an overview of database concepts, including the definition and importance of databases, the role of Database Management Systems (DBMS), and the advantages of using a DBMS. It explains data abstraction, data models, and the relational database model, detailing key components such as keys, referential integrity, and SQL commands. Additionally, it introduces MySQL as an open-source RDBMS and outlines SQL's various commands for managing databases.

Uploaded by

Sanjay Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Chapter 11

Informatics Practices Class XI ( As per CBSE


Board)
DATABASE CONCEPTS

A database is a collection of DATA/INFORMATION that is


organized so that it can be easily accessed, managed and
updated.
In Database ,Data is organized into rows, columns and tables,
and it is indexed to make it easier to find relevant information.
It works like a container which contains the various object like
Tables, Queries, Reports etc. in organized way.
WHY DO WE NEED DATABASE
 To manage large chunks of data: if size of data increases into thousands of records, it
will simply create a problem to manage. Database can manage large amount of data.
 Accuracy: Through validation rule in database ,data accuracy can be maintained.
 Ease of updating data: With the database, we can flexibly update the data
according to our convenience. Moreover, multiple people can also edit data at
same time.
 Security of data: With databases we have security groups and privileges to restrict
access.
 Data integrity: In databases, we can be assured of accuracy and consistency
of data due to the built in integrity checks and access controls.
Database Management System(DBMS)
A DBMS refers to a software that is responsible for storing, maintaining
and utilizing database in an efficient way.

A Database along with DBMS software is called Database System.

Example of DBMS software are Oracle, MS SQL Server, MS Access, Paradox,


DB2 and MySQL etc.
MySQL is open source and freeware DBMS.
Advantages of a DBMS
A DBMS has several advantages over traditional data processing techniques. Following are
advantages of data processing techniques:
a. Control of Data Redundancy- Duplication of data leads to wastage of storage space. A
DBMS eliminates data redundancy by integrating the files so that multiple copies of the same
data are not stored.
b. Data Consistency- DBMS provides data consistency to a large extent as the changes made
at one place are reflected at all other places or to all the users.
c. Sharing of Data- Data can be shared among different applications and programs.
d. Reduced programming effort- A DBMS saves a lot of programming effort since a user need
not write programs for query processing. It provides easy retrieval of data.
e. Database Enforces Standards- With centralized control of the database the database
administrator can ensure that the database standards are followed.
f. Privacy and Security- Data Security refers to protection of data against accidental or
intentional disclosure to unauthorized persons.
Data Abstraction
It is a process of hiding the implementation details (such as how the data is stored and
maintained) and representing only the essential features to simplify user’s interaction
with the system.
Different levels of abstraction are:
Physical Level/Internal Level- It describes how the data is actually stored in the
memory.
Logical/Conceptual Level- It describes what data are stored and what relationship
exist among those data.
View Level/External Level- It describes how the data is represented i.e in the form
of rows and tables.
Data Model- Way of data representation
Data model is a model or presentation which shows How data is organized ? or stored in the
database. A data is modelled by one of the following given-
Relational Data Model
In this model data is organized into Relations or Tables (i.e. Rows and Columns). A row in a table
represents a relationship of data to each other and also called a Tuple or Record. A column is
called Attribute or Field.
Network Data Model
In this model, data is represented by collection of records and relationship among data is shown
by Links.
Hierarchical Data Model
In this model, Records are organized as Trees. Records at top level is called Root
record and this may contains multiple directly linked
children records.
Object Oriented Data Model
In this model, records are represented as a objects. The collection of similar types of object is
RELATIONAL DATABASE
A relational database is a collective set of multiple data sets organized by tables, records and columns. Relational
database establish a well-defined relationship between database tables. Tables communicate and share information,
which facilitates data searchability, organization and reporting.
A Relational database use Structured Query Language (SQL), which is a standard user application that provides an easy
programming interface for database interaction.
What are the properties of a relational
model?
The relational databases consist of the following
properties:
•Every row is unique
•All of the values present in a column hold the
same data type
•Values are atomic
•The columns sequence is not significant
•The rows sequence is not significant
•The name of every column is unique
Important terms in RDBMS:
Domain :It is a pool of values from which the actual actual values appearing in a given
column are drawn.
Tuple / Entity / Record - Rows of a table is called Tuple or Record.
Attribute/ Field- Column of a table is called Attribute or Field.
Degree - Number of columns (attributes) in a table.
Cardinality - Number of rows (Records) in a table.
VIEWS - are virtual tables that do not store any data of their own but display data stored in
other tables. In other words, VIEWS are nothing but SQL Queries. A view can contain all or a
few rows from a table. A MySQL view can show data from one table or many tables.

Keys in database-Keys are very important part of Relational database model. They are used to establish
and identify relationships between tables and also to uniquely identify any record or row of data inside a table.
A Key can be a single attribute or a group of attributes, where the combination may act as a key.
KEYS IN A DATABASE
Key plays an important role in relational database; it is used for identifying unique rows
from table & establishes relationship among tables on need.
Types of keys in DBMS
Unique key
•A unique key in SQL is the set of fields or columns of a table that helps us
uniquely identify records. The unique key guarantees the uniqueness of the
columns in the database. It is similar to the primary key but can accept a null
value, unlike it. A primary key constraint automatically defines a unique key
constraint. More than one unique key can exist in a table, unlike the primary key,
which can exist only once.
Primary key
•It is the first key which is used to identify one and only one instance
of an entity uniquely. An entity can contain multiple keys as we saw
in PERSON table. The key which is most suitable from those lists
become a primary key.
•In the EMPLOYEE table, ID can be primary key since it is unique for
each employee. In the EMPLOYEE table, we can even select
License_Number and Passport_Number as primary key since they are
also unique.
•For each entity, selection of the primary key is based on
requirement and developers.
2. Candidate key
•A candidate key is an attribute or set of an attribute which
can uniquely identify a tuple.
•The remaining attributes except for primary key are
considered as a candidate key. The candidate keys are as
strong as the primary key.
•For example: In the EMPLOYEE table, id is best suited for
the primary key. Rest of the attributes like SSN,
Passport_Number, and License_Number, etc. are
considered as a candidate key.
Foreign key
•Foreign keys are the column of the table which is used to
point to the primary key of another table.
•In a company, every employee works in a specific
department, and employee and department are two
different entities. So we can't store the information of the
department in the employee table. That's why we link
these two tables through the primary key of one table.
•We add the primary key of the DEPARTMENT table,
Department_Id as a new attribute in the EMPLOYEE table.
•Now in the EMPLOYEE table, Department_Id is the foreign
key, and both the tables are related.
ALTERNATE KEYS is a column or group of columns in a table that uniquely identify every row in that
table. A table can have multiple choices for a primary key but only one can be set as the primary key. All
the keys which are not primary key are called an Alternate Key Or Candidate key which is not a primary
key is known as alternate key.
Example:
Referential Integrity
It is a system of rules that a DBMS uses to ensure that relationship between records in
related s tables are valid, and that user’s don’t accidently delete or change related data.

Conditions for Referential Integrity:


a. The matching field from the primary table is a primary key.
b. The related columns have the same data type.
c. Both tables belongs to same database.
Rules for Referential Integrity:
d. A value entered in foreign key that doesn’t exist in the primary key of primary table gives error.
e. A record in primary key can't be deleted if it exist in foreign key of related table.
f. A record in primary key can't be changed if it exist in foreign key of related table.
KEYS IN A DATABASE
Introduction to MySQL
MySQL is an Open Source, Fast and Reliable Relational Database Management System (RDBMS)
software like Oracle, Sybase, MS SQL Server etc. It was developed by Michael Widenius and AKA
Monty and is alternative to many of the commercial RDBMS. MySQL has been named after
Monty’s daughter My. The logo of MySQL, the dolphin, is named as “Sakila”. It is a multi user
Database System.
The main features of MySQL are-
 Open Source & Free of Cost:
It is Open Source and available at free of cost.
 Portability:
It can be installed and run on any types of Hardware and OS like Linux, MS Windows or Mac etc.
 Security :
It creates secured database protected with password.
 Connectivity
It may connect various types of Network client using different protocols and Programming
Languages .
 Query Language
It uses SQL (Structured Query Language) for handling database.
Overview of SQL
SQL is a standard language for accessing and manipulating databases. SQL
commands are used to create, transform and retrieve from RDBMS and
also to create an interface between an user and database.

In order to access data from the MySQL database, all program and user must
use SQL (Structured Query Language). SQL is a set of commands that are
recognized by all the RDBMSs and has become a standard language for
database handling.

There are numerous version of SQL. The original version was developed at IBM’s
San Jose Research Laboratory with a name of Sequel, as a part of System R
project in 1970s. It was standardized by ANSI in 1986 by the name of SQL.
SQL is a Standard Query language, whereas MySQL is a DBMS Software based on SQL.
Features of MySQL:
i. Speed –
ii. Accuracy-
iii. Ease of use-
iv. Cost-
v. Query Language Support-
vi. Portability-
vii.Data types-
viii.Security-
ix. Connectivity-
x. Localization-
the chief inventor of MySQL was A. K. Monty(Michael Widenius). The name given
MySQL to it on the name of his daughter My.
Why SQL is required
SQL is required:
•To create new databases, tables and views
•To insert records in a database
•To update records in a database
•To delete records from a database
•To retrieve data from a database

What SQL does


•With SQL, we can query our database in several ways, using English-like statements.
•With SQL, a user can access data from a relational database management system.
•It allows the user to define the data in the database and manipulate it when needed.
•It allows the user to create and drop database and table.
•It allows the user to create a view, stored procedure, function in a database.
•It allows the user to set permission on tables, procedures, and views.
SQL Commands
•SQL commands are instructions. It is used to communicate with the database. It is also used to
perform specific tasks, functions, and queries of data.
•SQL can perform various tasks like create a table, add data to tables, drop the table, modify the
table, set permission for users.
Types of SQL Commands
MySQL follows SQL specifications for its commands . These SQL commands can be
categorized as -
 Data Definition Language (DDL)
These SQL commands are used to create, alter and delete database objects like table,
views, index etc.
Example : CREATE , ALTER , DROP etc.
 Data Manipulation Language (DML)
These commands are used to insert, delete, update and retrieve the stored records from the
table.
Ex. SELECT…., INSERT…, DELETE…, UPDATE…. etc.
 Transaction Control Language (TCL)
These commands are used to control the transaction. Ex. COMMIT, ROLLBACK,
SAVEPOINT etc.
 Data Control Language (DCL)
These commands are used to manipulate permissions or access rights to the tables etc.
Ex. GRANT , REVOKE etc.
Data Definition Language (DDL)
•DDL changes the structure of the table like creating a table, deleting a table, altering a table,
etc.
•All the command of DDL are auto-committed that means it permanently save all the changes in
the database.
Here are some commands that come under DDL:
•CREATE table tablename
•ALTER table tablename
•DROP table tablename
•TRUNCATE table tablename
CREATE It is used to create a new table in the database.
ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.
TRUNCATE: It is used to delete all the rows from the table and free the space containing the table.
DROP: It is used to delete both the structure and record stored in the table.
Data Manipulation Language
•DML commands are used to modify the database. It is responsible for all form of changes in the
database.
•The command of DML is not auto-committed that means it can't permanently save all the
changes in the database. They can be rollback.
Here are some commands that come under DML:
•INSERT into tablename
•UPDATE tablename
•DELETE from tablename

INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.

UPDATE: This command is used to update or modify the value of a column in the table.

DELETE: It is used to remove one or more row from a table.


Data Control Language
DCL commands are used to grant and take back authority from any database user.
Here are some commands that come under DCL:
•Grant
•Revoke
Grant: It is used to give user access privileges to a database.
1.GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

Revoke: It is used to take back permissions from the user.


1.REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

1.NULL-For unknown value of a column we are using null. If we want to


keep any column blank. We are using null with that column.
2.Not Null- If it is specified on a column we cannot keep the blank.
Transaction Control Language
TCL commands can only use with DML commands like INSERT, DELETE and UPDATE only.
These operations are automatically committed in the database that's why they cannot be used
while creating tables or dropping them.
Here are some commands that come under TCL:
•BEGIN
•COMMIT
•ROLLBACK
•SAVEPOINT

Rollback: Rollback command is used to undo transactions that have not already been saved to
the database.
SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the
entire transaction.
Commit: Commit command is used to save all the transactions to the database.
Data Query Language
DQL is used to fetch the data from the database.
It uses only one command:
SELECT: This is the same as the projection operation of relational algebra. It is used to select the
attribute based on the condition described by WHERE clause.
Syntax:
1.SELECT expressions
2.FROM TABLES
3.WHERE conditions;
For example:
4.SELECT emp_name
5.FROM employee
6.WHERE age > 20;
SQL Data Types
Data types are used to represent the nature of the data that can be stored in the database table.
For example, in a particular column of a table, if we want to store a string type of data then we will
have to declare a string data type of this column.
Data types mainly classified into three categories for every database.
•String Data types
•Numeric Data types
•Date and time Data types
CHAR(Size) It is used to specify a fixed length string that can contain numbers, letters, and

special characters. Its size can be 0 to 255 characters. Default is 1.

VARCHAR(Size) It is used to specify a variable length string that can contain numbers, letters,

and special characters. Its size can be from 0 to 65535 characters.

BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size parameter specifies

the column length in the bytes. Default is 1.

VARBINARY(Size) It is equal to VARCHAR() but stores binary byte strings. Its size parameter

specifies the maximum column length in bytes.

TEXT(Size) It holds a string that can contain a maximum length of 255 characters.

TINYTEXT It holds a string with a maximum length of 255 characters.


MEDIUMTEXT It holds a string with a maximum length of 16,777,215.

LONGTEXT It holds a string with a maximum length of 4,294,967,295 characters.

ENUM(val1, val2, It is used when a string object having only one value, chosen from a list of

val3,...) possible values. It contains 65535 values in an ENUM list. If you insert a value

that is not in the list, a blank value will be inserted.

SET( val1,val2,va It is used to specify a string that can have 0 or more values, chosen from a list of

l3,....) possible values. You can list up to 64 values at one time in a SET list.

BLOB(size) It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.
MySQL Numeric Data Types

BIT(Size) It is used for a bit-value type. The number of bits per value is specified in size. Its size can
be 1 to 64. The default value is 1.

INT(size) It is used for the integer value. Its signed range varies from -2147483648 to 2147483647
and unsigned range varies from 0 to 4294967295. The size parameter specifies the max
display width that is 255.

INTEGER(size) It is equal to INT(size).

FLOAT(size, d) It is used to specify a floating point number. Its size parameter specifies the total number
of digits. The number of digits after the decimal point is specified by d parameter.

FLOAT(p) It is used to specify a floating point number. MySQL used p parameter to determine
whether to use FLOAT or DOUBLE. If p is between 0 to24, the data type becomes FLOAT ().
If p is from 25 to 53, the data type becomes DOUBLE().
DOUBLE(size, d) It is a normal size floating point number. Its size parameter specifies the total
number of digits. The number of digits after the decimal is specified by d parameter.

DECIMAL(size, d) It is used to specify a fixed point number. Its size parameter specifies the total
number of digits. The number of digits after the decimal parameter is specified
by d parameter. The maximum value for the size is 65, and the default value is 10.
The maximum value for d is 30, and the default value is 0.

DEC(size, d) It is equal to DECIMAL(size, d).

BOOL It is used to specify Boolean values true and false. Zero is considered as false, and
nonzero values are considered as true.
MySQL Date and Time Data Types
DATE It is used to specify date format YYYY-MM-DD. Its supported range is from '1000-
01-01' to '9999-12-31'.

DATETIME(fsp) It is used to specify date and time combination. Its format is YYYY-MM-DD
hh:mm:ss. Its supported range is from '1000-01-01 00:00:00' to 9999-12-31
23:59:59'.

TIMESTAMP(fsp) It is used to specify the timestamp. Its value is stored as the number of seconds
since the Unix epoch('1970-01-01 00:00:00' UTC). Its format is YYYY-MM-DD
hh:mm:ss. Its supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09
03:14:07' UTC.

TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss. Its supported range
is from '-838:59:59' to '838:59:59'

YEAR It is used to specify a year in four-digit format. Values allowed in four digit format
from 1901 to 2155, and 0000.
SQL Operators
SQL statements generally contain some reserved words or characters that are used to perform
operations such as comparison and arithmetical operations etc. These reserved words or
characters are known as operators.
Generally there are three types of operators in SQL:
1.SQL Arithmetic Operators
2.SQL Comparison Operators
3.SQL Logical Operators
SQL Arithmetic Operators:

Operators Descriptions Examples


+ It is used to add containing values of a+b will give 150
both operands
- It subtracts right hand operand from a-b will give -50
left hand operand
* It multiply both operand's values a*b will give 5000
/ It divides left hand operand by right b/a will give 2
hand operand
% It divides left hand operand by right b%a will give 0
hand operand and returns reminder
SQL Comparison Operators:
Operator Description Example

= Examine both operands value that are equal or not,if (a=b) is not true
yes condition become true.

!= This is used to check the value of both operands (a!=b) is true


equal or not,if not condition become true.

<> Examines the operand's value equal or not, if values (a<>b) is true
are not equal condition is true

> Examine the left operand value is greater than right (a>b) is not true
Operand, if yes condition becomes true
< Examines the left operand value is less than right (a<="" td="">
Operand, if yes condition becomes true
>= Examines that the value of left operand is greater than (a>=b) is not true
or equal to the value of right operand or not,if yes
condition become true
<= Examines that the value of left operand is less than or (a<=b) is true
equal to the value of right operand or not, if yes
condition becomes true
!< Examines that the left operand value is not less than (a!<="" td="">
the right operand value
!> Examines that the value of left operand is not greater (a!>b) is true
than the value of right operand
SQL Logical Operators:
Operator Description

ALL this is used to compare a value to all values in another value set.

AND this operator allows the existence of multiple conditions in an SQL


statement.

ANY this operator is used to compare the value in list according to the
condition.

BETWEEN this operator is used to search for values, that are within a set of values

IN this operator is used to compare a value to that specified list value


NOT the NOT operator reverse the meaning of any logical operator

OR this operator is used to combine multiple conditions in SQL statements

EXISTS the EXISTS operator is used to search for the presence of a row in a specified
table
LIKE this operator is used to compare a value to similar values using wildcard
operator

You might also like