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

DBMS Solution

The document contains the SQL commands and output from interacting with a MySQL database called 'bank'. It shows the user connecting to the database, viewing existing tables, and running various queries on the tables like selecting, updating, aggregating and indexing data. Some key things summarized: - The database contains tables for borrow, branch, customer and deposit information - Queries are run to find depositors by amount, customer details, branch averages, and create views of filtered data - Data is updated, like changing a customer's city, and indexes are created for tables The document demonstrates common SQL operations on a sample bank database scheme.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

DBMS Solution

The document contains the SQL commands and output from interacting with a MySQL database called 'bank'. It shows the user connecting to the database, viewing existing tables, and running various queries on the tables like selecting, updating, aggregating and indexing data. Some key things summarized: - The database contains tables for borrow, branch, customer and deposit information - Queries are run to find depositors by amount, customer details, branch averages, and create views of filtered data - Data is updated, like changing a customer's city, and indexes are created for tables The document demonstrates common SQL operations on a sample bank database scheme.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

ubuntu@ubuntu-virtual-machine:~$ sudo mysql

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| bank |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

*********************************************************9 10 11
12*******************************************************************
mysql> use bank;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_bank |
+----------------+
| borrow |
| branch |
| customer |
| deposit |
+----------------+
4 rows in set (0.00 sec)

mysql> select * from borrow;


+--------+--------+--------------+--------+
| loanno | cname | bname | amount |
+--------+--------+--------------+--------+
| 2001 | Anil | bank of maha | 12000 |
| 2002 | aarti | bank of maha | 30000 |
| 2003 | prachi | bank of maha | 0 |
| 2004 | Akash | peryridge | 450000 |
| 2005 | Atul | peryridge | 500000 |
| 2006 | Isha | union | 50000 |
| 2007 | sunil | union | 560000 |
| 2008 | avanti | union | 1000 |
| 2009 | isha | karolbag | 11000 |
| 2010 | anjali | karolbag | 11000 |
| 2011 | kali | karolbag | 1000 |
| 2012 | rucha | aandra | 10400 |
| 2013 | ira | aandra | 200 |
| 2014 | priyal | aandra | 2300 |
+--------+--------+--------------+--------+
14 rows in set (0.00 sec)

mysql> select * from branch;


+--------------+--------+
| bname | city |
+--------------+--------+
| peryridge | pune |
| bank of maha | pune |
| aandra | bombay |
| aandra | pune |
| union | nagpur |
| karolbag | nashik |
| union | nashik |
| union | pune |
+--------------+--------+
8 rows in set (0.00 sec)

mysql> select * from customer;


+--------+--------+
| cname | city |
+--------+--------+
| Anil | nashik |
| Akash | pune |
| Atul | pune |
| Isha | nashik |
| sunil | pune |
| sushma | pune |
| isha | pune |
| anjali | nashik |
| kali | nashik |
| aarti | pune |
| prachi | pune |
| prachi | pune |
| rucha | bombay |
| priyal | bombay |
| ira | pune |
| avanti | bombay |
+--------+--------+
16 rows in set (0.00 sec)

mysql> select * from deposit;


+-------+--------+--------------+--------+------------+
| actno | cname | bname | amount | adate |
+-------+--------+--------------+--------+------------+
| 1001 | Anil | bank of maha | 20000 | 2002-10-11 |
| 1002 | Akash | peryridge | 4000 | 1996-12-15 |
| 1003 | Atul | peryridge | 4000 | 1997-04-15 |
| 1004 | Isha | union | 6000 | 1997-06-15 |
| 1005 | sunil | union | 60000 | 1996-06-15 |
| 1006 | sushma | maha | 7000 | 1997-04-25 |
| 1007 | isha | karolbag | 17000 | 1997-01-16 |
| 1008 | anjali | karolbag | 17800 | 1998-01-16 |
| 1009 | kali | karolbag | 17800 | 1996-05-16 |
| 1010 | aarti | bank of maha | 4500 | 1996-04-15 |
| 1011 | prachi | bank of maha | 40000 | 1999-04-15 |
| 1012 | rucha | aandra | 500 | 1997-04-23 |
| 1013 | priyal | aandra | 500 | 1997-03-13 |
| 1014 | ira | aandra | 1500 | 1996-04-12 |
| 1015 | avanti | union | 15000 | 1997-04-12 |
+-------+--------+--------------+--------+------------+
15 rows in set (0.00 sec)

mysql> #1 names of depositers having amt > 4000


mysql> select cname
-> from deposit
-> where amount > 4000;
+--------+
| cname |
+--------+
| Anil |
| Isha |
| sunil |
| sushma |
| isha |
| anjali |
| kali |
| aarti |
| prachi |
| avanti |
+--------+
10 rows in set (0.00 sec)

mysql> #2 acc date of customer anil


mysql> select adate
-> from deposit
-> where cname='anil';
+------------+
| adate |
+------------+
| 2002-10-11 |
+------------+
1 row in set (0.00 sec)

mysql> #3 show acc no, amt of customers who have opened acc between 1-12-96 and 1-
5-97
mysql> select actno, amount
-> from deposit
-> where adate between '1-12-1996' and '1-5-1997';
Empty set, 30 warnings (0.00 sec)

mysql> #3 show acc no, amt of customers who have opened acc between 1-12-96 and 1-
5-97
mysql> select actno, amount
-> from deposit
-> where adate between '1996-12-1' and '1997-5-1';
+-------+--------+
| actno | amount |
+-------+--------+
| 1002 | 4000 |
| 1003 | 4000 |
| 1006 | 7000 |
| 1007 | 17000 |
| 1012 | 500 |
| 1013 | 500 |
| 1015 | 15000 |
+-------+--------+
7 rows in set (0.00 sec)

mysql> #4 avg acc balance at peryridge branch


mysql> select avg(amount)
-> from deposit
-> where bname='peryridge';
+-------------+
| avg(amount) |
+-------------+
| 4000.0000 |
+-------------+
1 row in set (0.01 sec)

IMP
mysql> #5 names of all branches where avg of amount > 1200
mysql> select bname
-> from deposit
-> group by bname
-> having avg(amount)>1200;
+--------------+
| bname |
+--------------+
| bank of maha |
| peryridge |
| union |
| maha |
| karolbag |
+--------------+
5 rows in set (0.00 sec)

mysql> #6 delete depositors having deposit less than 5000


mysql> delete
-> from deposit
-> where amount<4000;
Query OK, 3 rows affected (0.01 sec)

mysql> select * from deposit;


+-------+--------+--------------+--------+------------+
| actno | cname | bname | amount | adate |
+-------+--------+--------------+--------+------------+
| 1001 | Anil | bank of maha | 20000 | 2002-10-11 |
| 1002 | Akash | peryridge | 4000 | 1996-12-15 |
| 1003 | Atul | peryridge | 4000 | 1997-04-15 |
| 1004 | Isha | union | 6000 | 1997-06-15 |
| 1005 | sunil | union | 60000 | 1996-06-15 |
| 1006 | sushma | maha | 7000 | 1997-04-25 |
| 1007 | isha | karolbag | 17000 | 1997-01-16 |
| 1008 | anjali | karolbag | 17800 | 1998-01-16 |
| 1009 | kali | karolbag | 17800 | 1996-05-16 |
| 1010 | aarti | bank of maha | 4500 | 1996-04-15 |
| 1011 | prachi | bank of maha | 40000 | 1999-04-15 |
| 1015 | avanti | union | 15000 | 1997-04-12 |
+-------+--------+--------------+--------+------------+
12 rows in set (0.00 sec)

mysql> #7 create view on deposit table


mysql> create view deposit_view(cname,amount) AS
-> select cname, amount
-> from deposit
-> where amount>5000;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from deposit_view;


+--------+--------+
| cname | amount |
+--------+--------+
| Anil | 20000 |
| anjali | 17800 |
| avanti | 15000 |
| Isha | 6000 |
| isha | 17000 |
| kali | 17800 |
| prachi | 40000 |
| sunil | 60000 |
| sushma | 7000 |
+--------+--------+
9 rows in set (0.00 sec)

##################################### 10 ########################################
mysql> ##10
mysql> #1 all branches in city bombay
mysql> select bname
-> from branch
-> where city='bombay';
+--------+
| bname |
+--------+
| aandra |
+--------+
1 row in set (0.00 sec)

mysql> #2 show all acc no and amount of depositors


mysql> select actno, amount
-> from deposit;
+-------+--------+
| actno | amount |
+-------+--------+
| 1001 | 20000 |
| 1002 | 4000 |
| 1003 | 4000 |
| 1004 | 6000 |
| 1005 | 60000 |
| 1006 | 7000 |
| 1007 | 17000 |
| 1008 | 17800 |
| 1009 | 17800 |
| 1010 | 4500 |
| 1011 | 40000 |
| 1015 | 15000 |
+-------+--------+
12 rows in set (0.00 sec)

mysql> #3 change city of anil from pune to mumbai


mysql> alter table customer
-> modify city='mumbai'
-> where cname='anil';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'='mumbai'
where cname='anil'' at line 2
mysql> update customer
-> set city='mumbai'
-> where cname='anil';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from customer;


+--------+--------+
| cname | city |
+--------+--------+
| Anil | mumbai |
| Akash | pune |
| Atul | pune |
| Isha | nashik |
| sunil | pune |
| sushma | pune |
| isha | pune |
| anjali | nashik |
| kali | nashik |
| aarti | pune |
| prachi | pune |
| prachi | pune |
| rucha | bombay |
| priyal | bombay |
| ira | pune |
| avanti | bombay |
+--------+--------+
16 rows in set (0.00 sec)

mysql> #4 find no of depositors in bank


mysql> select count(actno)
-> from deposit;
+--------------+
| count(actno) |
+--------------+
| 12 |
+--------------+
1 row in set (0.00 sec)

mysql> #5 cal min,max amount of customers


mysql> select min(amount)
-> from deposit;
+-------------+
| min(amount) |
+-------------+
| 4000 |
+-------------+
1 row in set (0.00 sec)

mysql> select max(amount) from deposit;


+-------------+
| max(amount) |
+-------------+
| 60000 |
+-------------+
1 row in set (0.01 sec)

mysql> #6 create index on deposit


mysql> create index deposit_info
-> on deposit(cname,amount);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> #7 create view on borrow table


mysql> create view borrow_view(cname,amount) AS
-> select cname, amount
-> from borrow
-> where amount>5000;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from borrow_view;


+--------+--------+
| cname | amount |
+--------+--------+
| Anil | 12000 |
| aarti | 30000 |
| Akash | 450000 |
| Atul | 500000 |
| Isha | 50000 |
| sunil | 560000 |
| isha | 11000 |
| anjali | 11000 |
| rucha | 10400 |
+--------+--------+
9 rows in set (0.00 sec)

##################################### 11 ########################################
mysql> #1 display acc date of amil
mysql> select adate
-> from deposit
-> where cname='anil';
+------------+
| adate |
+------------+
| 2002-10-11 |
+------------+
1 row in set (0.00 sec)

mysql> #2 modify size of attribute of amount in deposite


mysql> desc deposit;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| actno | int | NO | PRI | NULL | |
| cname | varchar(20) | YES | MUL | NULL | |
| bname | varchar(20) | YES | | NULL | |
| amount | bigint | YES | | NULL | |
| adate | date | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> alter table deposit


-> modify amount int;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc deposit;


+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| actno | int | NO | PRI | NULL | |
| cname | varchar(20) | YES | MUL | NULL | |
| bname | varchar(20) | YES | | NULL | |
| amount | int | YES | | NULL | |
| adate | date | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> #3 names of customers live in city pune
mysql> select cname
-> from customer
-> where city='pune';
+--------+
| cname |
+--------+
| Akash |
| Atul |
| sunil |
| sushma |
| isha |
| aarti |
| prachi |
| prachi |
| ira |
+--------+
9 rows in set (0.00 sec)

mysql> #4 select names of city where branch karolbag is located


mysql> select city
-> from branch
-> where bname='karolbag';
+--------+
| city |
+--------+
| nashik |
+--------+
1 row in set (0.00 sec)

mysql> #5 find number of tuples in customer relation


mysql> select count(*)
-> from customer;
+----------+
| count(*) |
+----------+
| 16 |
+----------+
1 row in set (0.01 sec)

mysql> #6 delete all record of customer sunil


mysql> delete
-> from deposit
-> where cname='sunil';
Query OK, 1 row affected (0.02 sec)

mysql> select * from deposit;


+-------+--------+--------------+--------+------------+
| actno | cname | bname | amount | adate |
+-------+--------+--------------+--------+------------+
| 1001 | Anil | bank of maha | 20000 | 2002-10-11 |
| 1002 | Akash | peryridge | 4000 | 1996-12-15 |
| 1003 | Atul | peryridge | 4000 | 1997-04-15 |
| 1004 | Isha | union | 6000 | 1997-06-15 |
| 1006 | sushma | maha | 7000 | 1997-04-25 |
| 1007 | isha | karolbag | 17000 | 1997-01-16 |
| 1008 | anjali | karolbag | 17800 | 1998-01-16 |
| 1009 | kali | karolbag | 17800 | 1996-05-16 |
| 1010 | aarti | bank of maha | 4500 | 1996-04-15 |
| 1011 | prachi | bank of maha | 40000 | 1999-04-15 |
| 1015 | avanti | union | 15000 | 1997-04-12 |
+-------+--------+--------------+--------+------------+
11 rows in set (0.00 sec)

mysql> #7 create view on deposit table


/*mysql> drop view deposit_view;
Query OK, 0 rows affected (0.01 sec)*/

mysql> create view deposit_view(cname,amount) as


-> select cname, amount
-> from deposit
-> where amount>20000;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from deposit_view;


+--------+--------+
| cname | amount |
+--------+--------+
| prachi | 40000 |
+--------+--------+
1 row in set (0.00 sec)

mysql>
#########################################################12########################
##########################
mysql> #1 display customer name living in city bombay & branch city nagpur
mysql> select cname
-> from deposit d, branch b, customer c
-> where b.city='nagpur' and c.city='bombay' and d.bname=b.bname and
c.cname=d.cname;
ERROR 1052 (23000): Column 'cname' in field list is ambiguous
mysql>
mysql>
mysql> select c.cname
-> from deposit d, branch b, customer c
-> where b.city='nagpur' and c.city='bombay' and d.bname=b.bname and
c.cname=d.cname;
+--------+
| cname |
+--------+
| avanti |
+--------+
1 row in set (0.00 sec)

##

You might also like