You are on page 1of 4

B.G.

Akash BCA 4th Semester SRN:01FB14CCA005

Lab #4 Date 4-2-2016


mysql> create database 2a;
Query OK, 1 row affected (0.00 sec)
mysql> use 2a;
Database changed
mysql> create table doctor(doc_id char(22) primary key, dname char(50) not
null, dob date not null, specialization char(150) not null, city char(100)
not null);
Query OK, 0 rows affected (0.06 sec)

mysql> desc doctor;


+----------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-----------+------+-----+---------+-------+
| doc_id | char(22) | NO | PRI | NULL | |
| dname | char(50) | NO | | NULL | |
| dob | date | NO | | NULL | |
| specialization | char(150) | NO | | NULL | |
| city | char(100) | NO | | NULL | |
+----------------+-----------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> create table patient(pat_id char(22) primary key, pname char(50) not
null, address char(200) not null, dob date not null);
Query OK, 0 rows affected (0.05 sec)

mysql> desc patient;


+---------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-----------+------+-----+---------+-------+
| pat_id | char(22) | NO | PRI | NULL | |
| pname | char(50) | NO | | NULL | |
| address | char(200) | NO | | NULL | |
| dob | date | NO | | NULL | |
+---------+-----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> create table check_up(doc_id char(22) not null, pat_id char(22) not
null, cdate date not null, diagnosis char(240) not null, fee numeric(22,2)
not null, foreign key (doc_id) references doctor (doc_id) on delete cascade,
foreign key (pat_id) references patient (pat_id) on delete cascade,primary
key(doc_id,pat_id,cdate));
Query OK, 0 rows affected (0.10 sec)

mysql> desc check_up;


+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| doc_id | char(22) | NO | PRI | NULL | |
| pat_id | char(22) | NO | PRI | NULL | |
| cdate | date | NO | PRI | NULL | |
| diagnosis | char(240) | NO | | NULL | |
| fee | decimal(22,2) | NO | | NULL | |
+-----------+---------------+------+-----+---------+-------+

Faculty Of Computer Applications DBMS Lab


B.G.Akash BCA 4th Semester SRN:01FB14CCA005
5 rows in set (0.00 sec)

mysql> insert into doctor values("001","Akash",'1981',"ENT","Banglore");


Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> insert into doctor values("002","Yash",'1981',"Brain","Banglore");


Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> insert into doctor


values("003","Supradip",'1981',"Lungs","Banglore");
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> update doctor set dob='1981-01-01' where doc_id = "001";


Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> update doctor set dob='1981-01-01' where doc_id = "002";


Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> update doctor set dob='1981-01-01' where doc_id = "003";


Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> insert into doctor values("004","Rakshit",'1981-01-


01',"Heart","Banglore");
Query OK, 1 row affected (0.03 sec)

mysql> insert into doctor values("005","Sujit",'1981-01-


01',"Liver","Banglore");
Query OK, 1 row affected (0.04 sec)

mysql> select * from doctor;


+--------+----------+------------+----------------+----------+
| doc_id | dname | dob | specialization | city |
+--------+----------+------------+----------------+----------+
| 001 | Akash | 1981-01-01 | ENT | Banglore |
| 002 | Yash | 1981-01-01 | Brain | Banglore |
| 003 | Supradip | 1981-01-01 | Lungs | Banglore |
| 004 | Rakshit | 1981-01-01 | Heart | Banglore |
| 005 | Sujit | 1981-01-01 | Liver | Banglore |
+--------+----------+------------+----------------+----------+
5 rows in set (0.00 sec)

mysql> insert into patient values("101","Vivek","Ranchi",'1991-01-01');


Query OK, 1 row affected (0.04 sec)

mysql> insert into patient values("102","Jogendar","Gujrath",'1991-01-01');


Query OK, 1 row affected (0.04 sec)

mysql> insert into patient values("103","Krishna","Banglore",'1991-01-01');


Query OK, 1 row affected (0.04 sec)

mysql> insert into patient values("104","Rahul","Calcuta",'1991-01-01');


Query OK, 1 row affected (0.03 sec)

Faculty Of Computer Applications DBMS Lab


B.G.Akash BCA 4th Semester SRN:01FB14CCA005

mysql> insert into patient values("105","Hari","Banglore",'1991-01-01');


Query OK, 1 row affected (0.03 sec)

mysql> select * from patient;


+--------+----------+----------+------------+
| pat_id | pname | address | dob |
+--------+----------+----------+------------+
| 101 | Vivek | Ranchi | 1991-01-01 |
| 102 | Jogendar | Gujrath | 1991-01-01 |
| 103 | Krishna | Banglore | 1991-01-01 |
| 104 | Rahul | Calcuta | 1991-01-01 |
| 105 | Hari | Banglore | 1991-01-01 |
+--------+----------+----------+------------+
5 rows in set (0.00 sec)

mysql> insert into check_up values("001","105",'2010-02-11',"viral


fever",500);
Query OK, 1 row affected (0.04 sec)

mysql> insert into check_up values("002","104",'2010-05-21',"migrane",500);


Query OK, 1 row affected (0.04 sec)

mysql> insert into check_up values("003","103",'2010-06-15',"cough",500);


Query OK, 1 row affected (0.04 sec)

mysql> insert into check_up values("004","101",'2010-06-15',"heart


attack",50000);
Query OK, 1 row affected (0.03 sec)

mysql> insert into check_up values("005","102",'2010-07-22',"gout",5000);


Query OK, 1 row affected (0.03 sec)

mysql> select * from check_up;


+--------+--------+------------+--------------+----------+
| doc_id | pat_id | cdate | diagnosis | fee |
+--------+--------+------------+--------------+----------+
| 001 | 105 | 2010-02-11 | viral fever | 500.00 |
| 002 | 104 | 2010-05-21 | migrane | 500.00 |
| 003 | 103 | 2010-06-15 | cough | 500.00 |
| 004 | 101 | 2010-06-15 | heart attack | 50000.00 |
| 005 | 102 | 2010-07-22 | gout | 5000.00 |
+--------+--------+------------+--------------+----------+
5 rows in set (0.00 sec)

mysql> select pname, address, dob from patient where pname like 'r%';
+-------+---------+------------+
| pname | address | dob |
+-------+---------+------------+
| Rahul | Calcuta | 1991-01-01 |
+-------+---------+------------+
1 row in set (0.00 sec)

mysql> select patient.pname, doctor.dname, check_up.cdate,


check_up.diagnosis from patient, doctor, check_up where

Faculty Of Computer Applications DBMS Lab


B.G.Akash BCA 4th Semester SRN:01FB14CCA005
patient.pat_id=check_up.pat_id and doctor.doc_id=check_up.doc_id;
+----------+----------+------------+--------------+
| pname | dname | cdate | diagnosis |
+----------+----------+------------+--------------+
| Hari | Akash | 2010-02-11 | viral fever |
| Rahul | Yash | 2010-05-21 | migrane |
| Krishna | Supradip | 2010-06-15 | cough |
| Vivek | Rakshit | 2010-06-15 | heart attack |
| Jogendar | Sujit | 2010-07-22 | gout |
+----------+----------+------------+--------------+
5 rows in set (0.00 sec)

mysql> select specialization, count(*) from doctor group by specialization;


+----------------+----------+
| specialization | count(*) |
+----------------+----------+
| Brain | 1 |
| ENT | 1 |
| Heart | 1 |
| Liver | 1 |
| Lungs | 1 |
+----------------+----------+
5 rows in set (0.00 sec)

mysql> select count(*),avg(fee) from check_up c, patient p, doctor d where


d.doc_id=c.doc_id and p.pat_id=c.pat_id and p.pname="Hari" group by
p.pat_id;
+----------+------------+
| count(*) | avg(fee) |
+----------+------------+
| 1 | 500.000000 |
+----------+------------+
1 row in set (0.00 sec)

mysql> notee;

Faculty Of Computer Applications DBMS Lab

You might also like