0% found this document useful (0 votes)
31 views30 pages

RDBMS

The document provides an overview of Relational Database Management Systems (RDBMS), including their characteristics, terminologies, and the use of MySQL. It explains the structure of databases, the importance of data integrity, and various commands for managing data such as DDL and DML. Additionally, it covers SQL syntax for creating databases and tables, applying constraints, and performing queries.

Uploaded by

sriramsahoo2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views30 pages

RDBMS

The document provides an overview of Relational Database Management Systems (RDBMS), including their characteristics, terminologies, and the use of MySQL. It explains the structure of databases, the importance of data integrity, and various commands for managing data such as DDL and DML. Additionally, it covers SQL syntax for creating databases and tables, applying constraints, and performing queries.

Uploaded by

sriramsahoo2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

PART – B

UNIT – 4

RELATIONAL DATABASE
MANAGEMENT SYSTEM
INTRODUCTION
A database is a collection of interrelated data. A database
comprises the information about a particular organization or an
enterprise. Database system are designed to manage large bodies of
information.
Management of data involves both defining structures for storage
of information and providing mechanism for the manipulation of
information. In addition, the database system must ensure the safety of
the information stored.
Database Management System (DBMS) is a software that enables
users to create, store, maintain and retrieve data from the database.
Database management system was first introduced in the year
1960 by Charles W. Bachman.
The popular DBMSs are MYSQL, PostgreSQL, Microsoft Access,
Objectives of Database
Oracle, Microsoft :
SQL Server, DB2 and Sybase.

 DBMS allows us to store the data in a well structured manner.


 The data stored can be retrieved using query.
 Data can be sorted, managed and manipulated in the database.
 The data is validated and inconsistencies are removed from the
database.
HARACTERSTICS OF DBMS
1. Databases Control Redundancy :
Data redundancy means having duplicate copies of the same
data in different database. Centralized system of DBMS reduces the
redundancy of data to a great extend but cannot eliminate it completely.

2. Databases Control Inconsistency :


When the same data is duplicated and changes are made at one
place, which is not propagated to the other place, it gives rise to
inconsistency. In this situation, the data is said to be inconsistent.
If we control redundancy then inconsistency can also be
controlled. The can be done by centralized system.
3. Databases Enforce Integrity :

Integrity of data means that the data in database is always


accurate, such that incorrect information cannot be stored in database. In
order to maintain the integrity of data, some integrity constraints are
enforced on the database.
4. Databases Allows Sharing of Data :

Several users can share the same data such that each user can
access the same data accordingly to his/her requirement. The database
ensured that not only the data is shared among users but also the data
5. Databases Enforce Standards :
The standards laid by an organization are important for its
efficient working. The standard centralized database is very helpful
during migration or interchanging of data.
6. Databases Ensure Data Security :

Databases can enforce access control that governs what data will
be visible to different class of user. DBMS provides a security and
authorization subsystem which the database administrator us to create
RDBMS
accounts and to specify account restriction.

Relational Database Management System was introduced in the


1970’s as the data needed to be evaluate in efficient and effective
manner.
RDBMS is a database system software that manage and maintain
data in tabular format. the data is organized into separate tables. Once
the tables have been set up, a relationship can be created to link them
together through the use of a common column is called a Relational
database.
DBMS TERMINOLOGIES
1. Domain:
It is pool of values or the collection (set) of possible values from
which the value for a column is derived.
2. Tables or Relation in a database :

Relational Databases store data or information in tables. A table


is organised in rows (tuple) and column (fields) like a worksheet appears
in a spread sheet.
3. Record :

The horizontal subset of the Table is known as a Row/Tuple. Each


row represents a record, which is a collection of data about a particular
4. Field :
entity such as person, place or thing.

The vertical subset of the Table is known as a Column/Attribute.


The term field is also often used for column. Each column has a unique
4. Keys :
name and the content within it must be of the same type.

A column or a combination of columns which can be used to


identify one or more rows (tuples) in a table is called a key of the table.
A. Primary Key:

A column or a group of columns in a table that uniquely identify


every row in that table is known as Primary Key. When more than one
column needs to be chosen primary key then such key is known as
Composite key.
B. Candidate Key :

A column or a group of columns that can identify each unique


record independently of any other data in a relation is called a Candidate
key. A primary key is selected from one of the candidate key. A table may
have more than one candidates keys but only one primary key.
C. Alternate Key :

A candidate key of a table which is not selected as the primary


key is called its Alternate Key.
D. Foreign Key :

A foreign key is used to represent the relationship between two


table. A foreign key is a field in the child table whose value is derived
from the primary key of master/parent table.

NOTE : The primary key column and the foreign key column must have
the same data type and size.
NTRODUCTION TO MY SQL
MySQL is a most widely used relational database management
system. It is free and open source application which w.as founded and
developed in Sweden by David Axmark, Allan Larsson and Michael
Widenius, who had worked together since the 1980s.
Characteristics of MySQL :

 MySQL is fast, easy to use and is very reliable.


 MySQL is a platform independent application which works on many
operating systems like Windows, UNIX, LINUX etc.
 MySQL is an easy to install RDBMS and is capable of handling large
data sets.
CATEGORY OFno
 It requires MY SQL
cost COMMAND
or payment for its usage.

1. Data Definition Language (DDL) Commands :


MySQL commands can be classified into the following two
categories :

The DDL commands are used to define the structure of the


database. It consists of creating, modifying and deleting database. It also
used to define keys and impose constraints on the columns on the table.
The DDL commands are,
2. Data Manipulation Language (DML) Commands :

The DML commands are used to insert, update, retrieve and


delete the records in the table. It is used to manipulate the data of the
table in the database.
The DML commands are,
SELECT - extracts data from a table
UPDATE - updates data in a table
DELETE - deletes data from a table
INSERT INTO - inserts new data into a table
MY SQL DATA TYPE

Data type indicates the type of data that you are storing in a
given table column. The data type of a column defines what value the
column can hold like text, numeric, date, time etc.
DAT DATA EXAMP
DESCRIBTION
A TYPE LE
A fixed-length string from 1 to 255
characters in length right-padded with
CHAR spaces to the specified length when 'Maths'
TEXT
(Size) stored. Values must be enclosed in single "Text"
quotes or double quotes
DATA EXAMPL
DATA DESCRIBTION
TYPE E
A variable-length string from 1 to 255
'Compute
VARCHA characters in length; i.e. VARCHAR(25).
TEXT r' "good
R (Size) Values must be enclosed in single
morning"
quotes or double quotes
It can represent number with or without
the fractional part. The maximum
DECIMA number of digits may be specified in the
Numer 17.32
L size parameter. The maximum number
ic 345
(size, d) of digits to the right of the decimal point
is specified in the d parameter. It takes 8
bytes for storage.
Numer INT Or It is used for storing integer values. You
ic INTEGE can specify a width upto 11. It takes 4 76
R bytes for storage.
It represents the date including day,
month and year. The default format is '2009-07-
Date DATE
“YYYY-MM-DD”. It takes 3 bytes for 02
storage.
It represents time. Format: HH:MM:SS '-
USING MY SQL
 MySQL is case sensitive.
 The SQL statement always ends with ( ; ).
 Do not use ; in a multiline SQL statement, press only enter key.
Creating a Database :
CREATE command is used to create a database in MySQL.

Syntax : CREATE DATABASE <database-name>;

Example : mysql> CREATE DATABASE School ;


Opening / Using a Database :

USE command is used to create a database in MySQL.

Syntax : USE <database-name>;

Example : mysql> USE School ;


Viewing the Current Database :
Use SELECT command along with in-built function
DATABASE( ); to view the current database in MySQL.

Syntax : SELECT DATABASE();

Example : It will display your current database “School” ;

Creating a Table:

CREATE TABLE command is used to create a Table in MySQL.

Syntax : CREATE TABLE <table-name> (<ColumnName1><DataType1>,

<ColumnName2><DataType2>………….
<ColumnNameN><DataTypeN>;

Example : mysql> CREATE TABLE Student (Roll_No INTEGER, Name


VARCHAR(25),
Date_of_Birth Date) ;
PPLYING CONSTRAINTS IN TABLES :
MySQL provides data validation rules that can be applied on
fields/attributes called Constraints. Constraints are certain type of
restrictions on the data values that a field/attribute can have.

Constrain Purpose
ts
Primary The column which can uniquely identify each row in a
Key table. Primary key field cannot contain NULL and
Duplicate values.
Not Null It ensures that a column cannot have NULL values, where
NULL means missing/Unknown/ Not applicable value.
Foreign Key The column in the child table which refers to value of an
field defined as primary key in another table.
Unique It ensure that all values in a column are distinct, but Null
value is acceptable.
Default A default value specified for the column if no value is
provided.
Example :

1. CREATE TABLE Shoes


(Code CHAR(4) PRIMARY KEY,
Name VARCHAR(20),
type VARCHAR(10),
size INT(2),
cost DECIMAL(6,2),
margin DECIMAL(4,2),
Qty INT(4));
OR
CREATE TABLE Shoes (Code CHAR(4), Name VARCHAR(20), type
VARCHAR(10),
size INT(2), cost DECIMAL(6,2), margin DECIMAL(4,2),Qty INT(4),
PRIMARY KEY (Code));

2. CREATE TABLE bills


(Order_Num INT(4) PRIMARY KEY,
cust_code VARCHAR(4) PRIMARY KEY,
bill_Date DATE,
Bill_Amt DECIMAL(8,2));
OR
CREATE TABLE bills (Order_Num INT(4), cust_code
VARCHAR(4),bill_Date date,
Viewing Tables in the database :

To see a list of tables present in the current database, we can use SHOW
TABLE command.

Syntax : SHOW TABLEs;


Example : mysql>SHOW TABLES;
DIFYING THE STRUCTURE OF THE TABLES :
We can use ALTER TABLE command to change the structure of a
table by adding/removing/modifying the column, its data type and
constraints.
To add / Drop a column :
Syntax : ALTER TABLE <table_name>ADD/DROP
<column_name><columndefinition>
[first/after <field_name>];
Example : mysql>ALTER TABLE fee ADD name VARCHAR(25) after roll_no ;
To modify the data type, size of an existing column :

Syntax : ALTER TABLE <table_name> MODIFY


<column><new_definition>;
Example : mysql>ALTER TABLE fee MOIFY name CHAR(30);
To delete an existing column :
Syntax : ALTER TABLE <table_name> DROP <column_name>;
Example : mysql>ALTER TABLE fee DROP name;
To add Primary Key on a column :
Syntax : ALTER TABLE <table_name> ADD PRIMARY KEY
(<Fieldname(s)>);
Example : mysql>ALTER TABLE fee ADD PRIMARY KEY (rcpt_no);;
To Drop Primary Key from a column :
Syntax : ALTER TABLE <table_name> DROP PRIMARY KEY;
Example : mysql>ALTER TABLE fee DROP PRIMARY KEY;

To Add/ Remove NOT NULL constraint :


Syntax : ALTER TABLE <table_name> MODIFY
<column_name><datatype> NOT NULL;
Example : mysql>ALTER TABLE fee MODIFY amount DECIMAL (9,2) NOT
To Delete the structure of the Table :
NULL;
Syntax : DROP TABLE <table_name>;
Example : mysql>DROP TABLE fee;
To add new records in a table :
Syntax : INSERT INTO <table_name> (<columnname>) VALUES (value 1,
value 2, ……);
Example : INSERT INTO fee VALUES (505, “2022-06-07”, 1107, 5000,
To retrieve selected records from a table :
6746456789);
Syntax : SELECT <column name list>/* FROM <table_name> [WHERE
<condition> ORDER BY
<fielfname>];
Example :
1. To display all the columns from the table student.
mysql>SELECT * from student;
2. To display names of all the student from the table student.
mysql>SELECT name from student;
3. To display the details data with a given condition.
Mysql>SELECT * FROM student where gender = “M”;
mysql>SELECT rollno, date_of_fee FROM fee WHERE amount > 5000;
To display unique values only from a column :
Syntax : SELECT DISTINCT <column_name> FROM <table_name>;

Example : mysql> SELECT DISTINCT City FROM Student;


PERATORS USED IN SELECT COMMAND
1. Arithmetic Operator :
SQL support various Arithmetic operators to perform arithmetic
operations.
Operat
Description
or
+ addition of values
- Subtraction of values
* finding the product of values
/ Divide
% Modulo operator. Returns the remainder
2. Relational Operator :
Relational operators are used to compare values and gives a result in the
form of TRUE/False
Operat
Description
or
= Equal to
< Less than
> Greater than
<= Less than equal to
>= Greater than equal to
!= or Not equal to
<>
3. Logical Operator :
Logical operators are used to combine two relational expressions, it
returns TRUE/FALSE.
Operat
Description
or
AND Retunes TRUE, If both the conditions are true.
OR Retunes FALSE, If both the conditions are false.
Retunes TRUE, If the conditions is false otherwise returns
NOT
FALSE.
Example :
1. mysql> SELECT * FROM Student WHERE Gender = “M” AND
DOB>’2001-04-30’;
2. mysql> SELECT * FROM Student WHERE Gender = “M” OR
DOB>’2001-04-30’;
BETWEEN
3. mysql>Operator
SELECT *: FROM Student WHERE NOT Gender = “M”;
Between operators are used to retrieve those records that
matches with a range of values in a column.
Example :

Mysql> SELECT * FROM Employee WHERE Salary BETWEEN 48000 AND


66000;
IS Operator :
IS operator is used to compare equality with NULL whereas IS NOT
may be used for comparing the values not equal to NULL;
IN Operator :
IN operator is very useful when we wish to fetch selected records
which match a certain set of values.
LIKE Operator :
LIKE operators are used to retrieve the records having values
similat to the pattern. Pattern is made using wildcards. There are two
wildcards, these are,
1. % (Percent) - Used to represent zero, one or multiple characters.
2. _ (underscore) – Used to represent a single character.
Similarly many more patterns may be given as follows :
‘_ _ _ _’ matches any string with exactly four characters
‘S_ _ _ _’ matches any string of length of exactly 5 characters and starts
with letter ‘S’
‘S_ _ _ %’ matches any string of length of 4 or more characters and
starts with letter ‘S’
‘_ _ _H matches any string of length of exactly 4 characters and
terminates with letter ‘H’ ‘_ _ _ %’ matches any string with at least three
ORDER
or moreBY CLAUSE
characters
‘%in% matches any BY
The ORDER string which
Clause is containing ‘in’
used with SELECT statement to display
the output in a sorted order of the column mentioned. By default the
records are displayed in ascending order of the column name. Keyword
ASC is used with ORDER BY clause for displaying the list in ascending
order and keyword DESC is used with ORDER BY clause to display the
records in descending order
ALIAS NAME TO COLUMN
Alias Name is used for column to change the name of the
column while displaying the output using a SELECT command. The
column heading can be customized by using AS keyboard.
SERTING TEXT WITH IN THE QUERY SQL
To make the output more user friendly SQL supports inserting
text within the output display. The text is displayed only in the output
and no changes are made in the table.
UPDATE COMMAND
UPDATE command is used to modify data of records within the
table. It is a type of DML and is used to make changes in the values
entered in the table.
Syntax: UPDATE <tablename>
SET <columnname> = <value>, [<column name> = <value>,
….. ]
[WHERE <condition>];
The command can be used to update one or more columns and
WHERE clause is used for modifying the records that matches a criteria
DELETE COMMAND
DELETE Command is used to remove records from the table.
Syntax : DELETE from <tablename>
[Where <condition>];

mysql> DELETE FROM


STUDENT;

If no condition is
specified then all the records
of the table are removed i.e.
the table becomes empty.

You might also like