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

RDBMS

The document provides an overview of databases and Database Management Systems (DBMS), detailing their structure, functions, and types, including relational databases. It explains key concepts such as data integrity, redundancy, and access control, and introduces MySQL as a widely used relational database management system. Additionally, it covers SQL commands for data manipulation, data types, and constraints, along with examples of creating and managing tables.

Uploaded by

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

RDBMS

The document provides an overview of databases and Database Management Systems (DBMS), detailing their structure, functions, and types, including relational databases. It explains key concepts such as data integrity, redundancy, and access control, and introduces MySQL as a widely used relational database management system. Additionally, it covers SQL commands for data manipulation, data types, and constraints, along with examples of creating and managing tables.

Uploaded by

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

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, 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.
 We can print reports for displaying the data in summarized manner.
 The data can be shared between different users by granting access rights.
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.

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.

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.

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 can be shared among different applications.
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.

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 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.
It is pool of values or the collection (set) of possible values from which the value for
a column is derived.

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.

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 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 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. Keys are used to establish relationship
between the different tables and columns of a relational database.
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.

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.

A candidate key of a table which is not selected as the primary key is called its
Alternate 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.
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.

 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.
 It requires no cost or payment for its usage.

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,
a) CREATE DATABASE - creates a new database b) CREATE TABLE - creates a new table
c) ALTER TABLE - modifies a table d) DROP TABLE - deletes a table
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

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.

DATA DATA TYPE DESCRIBTION EXAMPLE


A fixed-length string from 1 to 255 characters in
length right-padded with spaces to the specified 'Maths'
TEXT CHAR (Size)
length when stored. Values must be enclosed in single "Text"
quotes or double quotes
DATA
DATA DESCRIBTION EXAMPLE
TYPE
A variable-length string from 1 to 255 characters in 'Computer'
VARCHAR
TEXT length; i.e. VARCHAR(25). Values must be enclosed "good
(Size)
in single quotes or double quotes morning"
It can represent number with or without the
fractional part. The maximum number of digits may
DECIMAL be specified in the size parameter. The maximum 17.32
Numeric
(size, d) number of digits to the right of the decimal point is 345
specified in the d parameter. It takes 8 bytes for
storage.
Numeric INT Or It is used for storing integer values. You can specify
76
INTEGER a width upto 11. It takes 4 bytes for storage.
It represents the date including day, month and
'2009-07-
Date DATE year. The default format is “YYYY-MM-DD”. It takes
02
3 bytes for storage.
It represents time. Format: HH:MM:SS '-838:59:59'
Time TIME
'838:59:59'
 MySQL is case sensitive.
 The SQL statement always ends with ( ; ).
 Do not use ; in a multiline SQL statement, press only enter key.

CREATE command is used to create a database in MySQL.

Syntax : CREATE DATABASE <database-name>;

Example : mysql> CREATE DATABASE School ;

USE command is used to create a database in MySQL.

Syntax : USE <database-name>;

Example : mysql> USE School ;


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” ;

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) ;
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.

Constraints Purpose
Primary Key The column which can uniquely identify each row in a 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.
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,
Bill_Amt DECIMAL(8,2),
PRIMARY KEY(Order_Num, cust_code));
To see a list of tables present in the current database, we can use SHOW TABLE command.

Syntax : SHOW TABLEs;


Example : mysql>SHOW 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.

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 ;

Syntax : ALTER TABLE <table_name> MODIFY <column><new_definition>;


Example : mysql>ALTER TABLE fee MOIFY name CHAR(30);

Syntax : ALTER TABLE <table_name> DROP <column_name>;


Example : mysql>ALTER TABLE fee DROP name;
Syntax : ALTER TABLE <table_name> ADD PRIMARY KEY (<Fieldname(s)>);
Example : mysql>ALTER TABLE fee ADD PRIMARY KEY (rcpt_no);;

Syntax : ALTER TABLE <table_name> DROP PRIMARY KEY;


Example : mysql>ALTER TABLE fee DROP PRIMARY KEY;

Syntax : ALTER TABLE <table_name> MODIFY <column_name><datatype> NOT NULL;


Example : mysql>ALTER TABLE fee MODIFY amount DECIMAL (9,2) NOT NULL;

Syntax : DROP TABLE <table_name>;


Example : mysql>DROP TABLE fee;
Syntax : INSERT INTO <table_name> (<columnname>) VALUES (value 1, value 2, ……);
Example : INSERT INTO fee VALUES (505, “2022-06-07”, 1107, 5000, 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;

Syntax : SELECT DISTINCT <column_name> FROM <table_name>;


Example : mysql> SELECT DISTINCT City FROM Student;
SQL support various Arithmetic operators to perform arithmetic operations.

Operator Description
+ addition of values
- Subtraction of values
* finding the product of values
/ Divide
% Modulo operator. Returns the remainder
Relational operators are used to compare values and gives a result in the form of TRUE/False

Operator Description
= Equal to
< Less than
> Greater than
<= Less than equal to
>= Greater than equal to
!= or <> Not equal to
Logical operators are used to combine two relational expressions, it returns TRUE/FALSE.

Operator Description
AND Retunes TRUE, If both the conditions are true.
OR Retunes FALSE, If both the conditions are false.
NOT Retunes TRUE, If the conditions is false otherwise returns 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’;
3. mysql> 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 used to compare equality with NULL whereas IS NOT may be used for
comparing the values not equal to NULL;
IN operator is very useful when we wish to fetch selected records which match a
certain set of values.
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 or more characters
‘%in% matches any string which containing ‘in’

The ORDER BY Clause is 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 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.
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 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 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