You are on page 1of 4

B.G.

Akash BCA 4th Semester SRN:01FB14CCA005

Lab #5 Date 26-2-2016


mysql> create database mus_26_2_16;
Query OK, 1 row affected (0.00 sec)

mysql> use mus_26_2_16;


Database changed
mysql> create table musician(musicianid char(11) primary key, mname char(55)
not null, dob date not null, specialized_instrument char(55) not null);
Query OK, 0 rows affected (0.06 sec)

mysql> create table instrument(instrumentid char(11) primary key, iname


char(55) not null, price numeric(12,2) not null, type char(100) not null);
Query OK, 0 rows affected (0.08 sec)

mysql> create table perform(musid char(11) not null, instid char(11) not
null, functiondate date not null, function char(200) not null, primary
key(musid,instid,functiondate), foreign key(musid) references
musician(musicianid) on delete cascade, foreign key(instid) references
instrument(instrumentid) on delete cascade);
Query OK, 0 rows affected (0.11 sec)

mysql> desc musician;


+------------------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+----------+------+-----+---------+-------+
| musicianid | char(11) | NO | PRI | NULL | |
| mname | char(55) | NO | | NULL | |
| dob | date | NO | | NULL | |
| specialized_instrument | char(55) | NO | | NULL | |
+------------------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc instrument;


+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| instrumentid | char(11) | NO | PRI | NULL | |
| iname | char(55) | NO | | NULL | |
| price | decimal(12,2) | NO | | NULL | |
| type | char(100) | NO | | NULL | |
+--------------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc perform;


+--------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-----------+------+-----+---------+-------+
| musid | char(11) | NO | PRI | NULL | |
| instid | char(11) | NO | PRI | NULL | |
| functiondate | date | NO | PRI | NULL | |
| function | char(200) | NO | | NULL | |
+--------------+-----------+------+-----+---------+-------+
4 rows in set (0.01 sec)

Faculty Of Computer Applications DBMS Lab


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

mysql> insert into musician values("101","Avicii",'1990-01-05',"flute");


Query OK, 1 row affected (0.04 sec)

mysql> insert into musician values("102","Martin_Garix",'1995-06-


25',"drums");
Query OK, 1 row affected (0.03 sec)

mysql> insert into musician values("103","Hardwell",'1989-06-17',"guitar");


Query OK, 1 row affected (0.04 sec)

mysql> insert into musician values("104","David_Guetta",'1985-02-


07',"keyboard");
Query OK, 1 row affected (0.04 sec)

mysql> insert into musician values("105","Aron_Chupa",'1988-12-27',"piano");


Query OK, 1 row affected (0.04 sec)

mysql> insert into instrument values("111","flute",'5000',"wind");


Query OK, 1 row affected (0.04 sec)

mysql> insert into instrument values("112","drums",'50000',"percussion");


Query OK, 1 row affected (0.03 sec)

mysql> insert into instrument values("113","guitar",'50000',"electric");


Query OK, 1 row affected (0.04 sec)

mysql> insert into instrument values("114","keyboard",'50000',"electric");


Query OK, 1 row affected (0.03 sec)

mysql> insert into instrument values("115","piano",'500000',"percussion");


Query OK, 1 row affected (0.05 sec)

mysql> insert into perform values("101","111",'2016-06-21',"tomorrow_land");


Query OK, 1 row affected (0.03 sec)

mysql> insert into perform values("102","112",'2016-06-22',"tomorrow_land");


Query OK, 1 row affected (0.04 sec)

mysql> insert into perform values("103","113",'2016-06-23',"tomorrow_land");


Query OK, 1 row affected (0.03 sec)

mysql> insert into perform values("104","114",'2016-06-23',"tomorrow_land");


Query OK, 1 row affected (0.04 sec)

mysql> insert into perform values("105","115",'2016-06-25',"tomorrow_land");


Query OK, 1 row affected (0.03 sec)

Faculty Of Computer Applications DBMS Lab


B.G.Akash BCA 4th Semester SRN:01FB14CCA005
mysql> select * from musician;
+------------+--------------+------------+------------------------+
| musicianid | mname | dob | specialized_instrument |
+------------+--------------+------------+------------------------+
| 101 | Avicii | 1990-01-05 | flute |
| 102 | Martin_Garix | 1995-06-25 | drums |
| 103 | Hardwell | 1989-06-17 | guitar |
| 104 | David_Guetta | 1985-02-07 | keyboard |
| 105 | Aron_Chupa | 1988-12-27 | piano |
+------------+--------------+------------+------------------------+
5 rows in set (0.00 sec)

mysql> select * from instrument;


+--------------+----------+-----------+------------+
| instrumentid | iname | price | type |
+--------------+----------+-----------+------------+
| 111 | flute | 5000.00 | wind |
| 112 | drums | 50000.00 | percussion |
| 113 | guitar | 50000.00 | electric |
| 114 | keyboard | 50000.00 | electric |
| 115 | piano | 500000.00 | percussion |
+--------------+----------+-----------+------------+
5 rows in set (0.00 sec)

mysql> select * from perform;


+-------+--------+--------------+---------------+
| musid | instid | functiondate | function |
+-------+--------+--------------+---------------+
| 101 | 111 | 2016-06-21 | tomorrow_land |
| 102 | 112 | 2016-06-22 | tomorrow_land |
| 103 | 113 | 2016-06-23 | tomorrow_land |
| 104 | 114 | 2016-06-23 | tomorrow_land |
| 105 | 115 | 2016-06-25 | tomorrow_land |
+-------+--------+--------------+---------------+
5 rows in set (0.00 sec)

mysql> select iname,price from instrument where type='electric';


+----------+----------+
| iname | price |
+----------+----------+
| guitar | 50000.00 |
| keyboard | 50000.00 |
+----------+----------+
2 rows in set (0.00 sec)

mysql> select i.iname,i.price from instrument i,perform p where


i.instrumentid=p.instid and function like 'tomorr%';
+----------+-----------+
| iname | price |
+----------+-----------+
| flute | 5000.00 |
| drums | 50000.00 |
| guitar | 50000.00 |
| keyboard | 50000.00 |
| piano | 500000.00 |

Faculty Of Computer Applications DBMS Lab


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

mysql> select m.mname,m.specialized_instrument,p.function from musician m,


perform p where m.musicianid=p.musid and functiondate like '2016%';
+--------------+------------------------+---------------+
| mname | specialized_instrument | function |
+--------------+------------------------+---------------+
| Avicii | flute | tomorrow_land |
| Martin_Garix | drums | tomorrow_land |
| Hardwell | guitar | tomorrow_land |
| David_Guetta | keyboard | tomorrow_land |
| Aron_Chupa | piano | tomorrow_land |
+--------------+------------------------+---------------+
5 rows in set, 1 warning (0.00 sec)

mysql> select specialized_instrument from musician m group by


specialized_instrument having count(distinct(m.musicianid))>1;
Empty set (0.01 sec)

mysql> notee;

Faculty Of Computer Applications DBMS Lab

You might also like