RDBMS Notes Unit 4
RDBMS Notes Unit 4
Collection of logically related data that has been recorded, organized and made
available for searching is called Database.
Banking
Online shopping
Payroll
Inventory management
Loan and investment
Reservation system And many more
What are the needs for a database?
Relation: a table is called relation. Another way we can say that collection of tuple
is called relation.
Tuple: A row of table is called tuple. In another way we can say that a single record
is called tuple
Domain: the data type of values in each column is called the Domain.
Candidate key
The key which is Primary key in another related table (relation) is called
Foreign Key.
A relation can have more than foreign keys.
What is MySQL? | Characteristics of MySQL
MySQL is one of the most popular Relational Database Management System
(RDBMS).
MySQL was originally founded and developed in Sweden by David Axmark,
Allan Larsson and Michael Widenius, who had worked together since the
1980s.
Characteristics of MySQL
It is free and Open Source software which does not require to pay for its
usage.
It is easy to use, quick and reliable.
It is platform independent software which works on many operating systems
like
Windows, UNIX, LINUX etc.
It is compatible with many programming languages including JAVA, C++,
PHP, PERL, etc.
It can handle large amount of data very efficiently and accurately.
What is SQL?
Syntax
Example:
Using a database
Syntax
USE <databasename>;
Example:
To view the name of current database we can use SELECT DATABASE(); command.
Syntax
SELECT DATABASE();
Example:
Example:
Screenshot:
Sometimes an attribute may not be allowed to leave blank. Hence Not Null
constraints can be associated in this case.
Example:
Screenshot:
Default Constraint
Screenshot:
Primary Key
Screenshot:
Foreign Key
it ensures relationship between relations. The main purpose of this constraint is to
check that data entered in one relation is consistent with the data entered in
another relation.
Example:
Here in this example Ino is the foreign key that references Ino of Item table which is
Primary key.
The SQL command for making Ino to foreign key in Order table is as follows:
Create Order
(
Ono int Primary Key,
Odate date,
Itemno int,
Qty int,
Total int,
FOREIGN KEY (Itemno) REFERENCES Item (Itemno)
);
Screen Shot:
Unique Key
Screenshot:
Example:
DESCRIBE EMPLOYEE;
ScreenShot
Drop table
Syntax:
Example:
It is used to modify structure of a table. Following are the alteration can be done
using this command:
Adding a column
Example:
Example:
A column can also be modified using Alter Table command as given below:
Screenshot:
How to add Primary Key?
This command is used to insert a tuple in a relation. We must specify the name of
the relation in which tuple is to be inserted and the values. The values must be in
the same order as specified during the Create Table command.
Syntax:
Example:
Screenshot:
Update command
Update command is used to modify the attribute values of one or more tuples in a
table.
Syntax:
UPDATE <tablename>
SET <expression>
WHERE <criteria>
Example:
UPDATE Item
SET Rate = 30
WHERE itemno = ‘i0001’;
Screenshot:
Delete command
Syntax:
Example:
Screenshot:
Select command
Syntax:
Code:
Screenshot:
Query2: Display itemname with its rate from item table.
Code:
Screenshot:
Code:
Code:
Screenshot:
Query5: retrieve item details which rate is less than 100 and qty is more
than 100.
Code:
Select * from item where rate < 100 and qty > 100;
Screenshot:
DISTINCT Command
Syntax:
Example
Screenshot
WHERE clause
Example:
Query5: retrieve item details which rate is less than 100 and qty is more
than 100.
Code:
Select * from item where rate < 100 and qty > 100;
Screenshot:
Example:
Screenshot:
Arithmetic operators
Relation operators
Logical operators
BETWEEN operators
IN operators
LIKE operators
Arithmetic operators
Relational operators
= Equal to
Logical operators
IN operator
LIKE operator
Order by clause