RDBMS
RDBMS
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.
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 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.
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.
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));
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;
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>];
If no condition is specified
then all the records of the table are
removed i.e. the table becomes
empty.