Mysql Tutorial: Introduction To Database
Mysql Tutorial: Introduction To Database
Mysql Tutorial: Introduction To Database
Introduction to Database
Introduction of MySQL
MySQL is an SQL (Structured Query Language)
based relational database management system
(DBMS)
MySQL is compatible with standard SQL
MySQL is frequently used by PHP and Perl
Commercial version of MySQL is also provided
(including technical support)
Resource
MySQL and GUI Client can be downloaded
from
http://dev.mysql.com/downloads/
Example
create database mydatabase
SQL Script for creating tables
The SQL script for creating database bank
can be found at
http://www.cs.kent.edu/~mabuata/DB10_lab/bank_db.sql
http://www.cs.kent.edu/~mabuata/DB10_lab/bank_data.sql
Find the customer names and their loan numbers for all customers
having a loan at some branch.
Find the names of all branches where the average account balance
is more than $500.
Find all customers who have a loan at the bank but do not
have an account at the bank
select distinct customer_name
from borrower
where customer_name not in
(select customer_name from depositor);
Nested Subquery
Find the names of all branches that have greater assets
than all branches located in Horseneck.
select branch_name
from branch
where assets > all
(select assets
from branch
where branch_city = Horseneck);
Create View (new feature in mysql 5.0)
A view consisting of branches and their customers
update account
set balance = balance 1.07
where balance > 800;
update account
set balance = balance 1.08
where balance 800;
Modification of Database
Increase all accounts with balances over $700 by 6%, all
other accounts receive 5%.
update account
set balance =case
when balance <= 700 then balance *1.05
else balance * 1.06
end;
Modification of Database
Delete the record of all accounts with balances below the
average at the bank.
delete from account
where balance < (select avg (balance) from account);