DatabaseSystem - Assignment 2 Nantawan TJ 6010
DatabaseSystem - Assignment 2 Nantawan TJ 6010
DatabaseSystem - Assignment 2 Nantawan TJ 6010
Nantawan Gantong
Student ID : 6010
**Insert data**
INSERT INTO `Employee` (`Emp_ID`, `Name`, `Job_ID`, `ID_Branch`) VALUES ('A01', 'Adam', 'J10', 'B01'), ('A02', 'Thomas ',
'J10', 'B02'), ('A03', 'Henry', 'J10', 'B03'), ('A04', 'Hunter\r\n', 'J10', 'B04'), ('A05', 'Jack', 'J10', 'B05'), ('D01', 'Johanna\r\n', 'J11',
'B01'), ('D02', 'Joey', 'J11', 'B02'), ('D03', 'Bob', 'J11', 'B03'), ('D04', 'Arun', 'J11', 'B04'), ('D05', 'TJ', 'J11', 'B05'), ('M01', 'Jin',
'J12', 'B01'), ('M02', 'Aya', 'J12', 'B02'), ('M03', 'Kim\r\n', 'J12', 'B03'), ('M04', 'Clark', 'J12', 'B04'), ('M05', 'Pink\r\n', 'J12', 'B05'),
('C01', 'Lala\r\n', 'J13', 'B01'), ('C02', 'Paula\r\n', 'J13', 'B02'), ('C03', 'Roy\r\n', 'J13', 'B03'), ('C04', 'Tailor', 'J13', 'B04'), ('C05',
'Ducklas', 'J13', 'B05');
**Create Table**
2. Musician
CREATE TABLE `db_9ab8b7_6010`.`Musician` ( `Emp_ID` VARCHAR(3) NOT NULL COMMENT 'X00' ,
`Name` VARCHAR(20) NOT NULL , `Phone` INT(10) NOT NULL COMMENT '000-0000000' , `Address` TEXT
NOT NULL , `Band_ID` INT (1) NOT NULL , PRIMARY KEY (`Name`)) ENGINE = MyISAM COMMENT =
'Musician';
**Insert data**
INSERT INTO `Musician` (`Emp_ID`, `Name`, `Phone`, `Address`, `Band_ID`) VALUES ('A01', 'Adam',
'0455555555', '34 Sydney rd\r\n', '1'), ('A02', 'Thomas', '0466666666', '45 Elizabate st\r\n', '2'), ('A03', 'Henry',
'0477777777', '6 King st\r\n', '3'), ('A04', 'Hunter', '0488888888', '2/2 spencer st\r\n', '4'), ('A05', 'Jack',
'0499999999', '300 collins st\r\n', '5');
**Create table**
3. Band
CREATE TABLE `db_9ab8b7_6010`.`Band` ( `Band_ID` INT(1) NOT NULL , `BandName` TEXT NOT NULL ,
PRIMARY KEY (`Band_ID`)) ENGINE = InnoDB COMMENT = 'Band';
**Insert data**
INSERT INTO `Band` (`Band_ID`, `BandName`) VALUES ('1', 'KoKo'), ('2', 'Lovelyhood'), ('3', 'Beary'), ('4',
'OSO'), ('5', 'Bettle')
**Create table**
4. Company
CREATE TABLE `db_9ab8b7_6010`.`Company` ( `ID_Branch` VARCHAR(3) NOT NULL COMMENT 'B00' ,
`Company name` TEXT NOT NULL , `Phone` INT(10) NOT NULL COMMENT '000-0000000' , `Country` TEXT
NOT NULL , PRIMARY KEY (`ID_Branch`)) ENGINE = InnoDB COMMENT = 'Company';
**Insert data**
INSERT INTO `Company` (`ID_Branch`, `Company name`, `Phone`, `Country`) VALUES ('B01', 'AUS rec.\r\n',
'023333333', 'Australia'), ('B02', 'Uk rec.', '024444444', 'United Kingdom'), ('B03', 'Japan rec.', '025555555',
'Japan'), ('B04', 'TH rec.', '26666666', 'Thailand'), ('B05', 'Ko rec.', '027777777', 'Korean');
**Create table**
5. Concert Hall
CREATE TABLE `db_9ab8b7_6010`.`ConcertHall` ( `Hall_ID` INT(3) NOT NULL , `Stage_size` VARCHAR(3)
NOT NULL , `SeatingCap` INT(4) NOT NULL , `City` TEXT NOT NULL , `Country` TEXT NOT NULL , PRIMARY
KEY (`Hall_ID`)) ENGINE = InnoDB
**Insert data**
INSERT INTO `ConcertHall` (`Hall_ID`, `Stage_size`, `SeatingCap`, `City`, `Country`) VALUES ('201', '30m',
'1000', 'Melbourne', 'Australia\r\n'), ('202', '40m', '1500', 'London', 'United Kingdom'), ('203', '50m', '2000',
'Osaka\r\n', 'Japan'), ('204', '60m', '2500', 'Bangkok\r\n', 'Thailand'), ('205', '70m', '3000', 'Seoul\r\n', 'Korean');
**Create table**
6. Job
CREATE TABLE `db_9ab8b7_6010`.`Job` ( `Job_ID` VARCHAR(3) NOT NULL COMMENT 'J00' , `JobTitle`
TEXT NOT NULL , `Salary` INT(4) NOT NULL , PRIMARY KEY (`Job_ID`)) ENGINE = InnoDB;
**Insert data**
INSERT INTO `Job` (`Job_ID`, `JobTitle`, `Salary`) VALUES ('J10', 'Musician', '5000'), ('J11', 'Director', '6000'),
('J12', 'Manager\r\n', '6500'), ('J13', 'Accountant', '6000'), ('J14', 'Assistant', '4500');
**Create table**
7. Album
CREATE TABLE `db_9ab8b7_6010`.`Album` ( `IdAlbum` VARCHAR(3) NOT NULL , `AlbumArt` TEXT NOT
NULL , `Title` TEXT NOT NULL , `Price` VARCHAR(4) NOT NULL , `Band_ID` INT(1) NOT NULL , PRIMARY
KEY (`IdAlbum`), INDEX `Band_ID` (`Band_ID`)) ENGINE = InnoDB;
**Insert data**
INSERT INTO `Album` (`IdAlbum`, `AlbumArt`, `Title`, `Price`, `Band_ID`) VALUES ('B01', 'Dark mode\r\n',
'Rock n Roll ', '100$', '1'), ('B02', 'Blue\r\n', 'Beater !', '150$', '2'), ('B03', 'Pink \r\n', 'Heart attack
', '150$', '3'), ('B04', 'Orangish ', 'Laliboo', '200$', '4'), ('B05', 'Greenish', 'Malayya', '150$', '5');
**Create table**
8. Song
CREATE TABLE `db_9ab8b7_6010`.`Song` ( `IdSong` VARCHAR(3) NOT NULL , `SongName` TEXT NOT
NULL , `Band_ID` INT(1) NOT NULL , `IdAlbum` VARCHAR(3) NOT NULL , `VDO_id` VARCHAR(3) NOT NULL
, PRIMARY KEY (`IdSong`), INDEX `Band_ID` (`Band_ID`), INDEX `IdAlbum` (`IdAlbum`), INDEX `VDO_id`
(`VDO_id`)) ENGINE = InnoDB COMMENT = 'Song';
**Insert data**
INSERT INTO `Song` (`IdSong`, `SongName`, `Band_ID`, `IdAlbum`, `VDO_id`) VALUES ('S01', 'Felling down',
'1', 'B01', 'V01'), ('S02', 'Just close your eyes', '2', 'B02', 'V02'), ('S03', 'Bring me the tear\r\n', '3', 'B03', 'V03'),
('S04', 'Happiness around me\r\n', '4', 'B04', 'V04'), ('S05', 'My life\r\n', '5', 'B05', 'V05');
**Create table**
9. Concert
CREATE TABLE `db_9ab8b7_6010`.`Concert` ( `Concert_Id` INT(4) NOT NULL , `ConcertName` TEXT NOT
NULL , `Time` TIME NOT NULL , `Date` DATE NOT NULL , `Hall_ID` INT(3) NOT NULL , `Band_ID` INT(1)
NOT NULL , PRIMARY KEY (`Concert_Id`), INDEX `Hall_ID` (`Hall_ID`), INDEX `Band_ID` (`Band_ID`))
ENGINE = InnoDB COMMENT = 'Concert';
**Insert data**
INSERT INTO `Concert` (`Concert_Id`, `ConcertName`, `Time`, `Date`, `Hall_ID`, `Band_ID`) VALUES ('3001',
'Rock n Roll', '18:00:00', '2017-01-01', '201', '1'), ('3002', 'Beater !', '19:00:00', '2018-03-03', '202', '2'), ('3003',
'3003 Heart attack', '20:00:00', '2019-04-06', '201', '3'), ('3004', 'Laliboo ', '21:00:00', '2019-10-05',
'203', '4'), ('3005', 'Malayya ', '22:00:00', '2020-12-30', '205', '5');
**Create table**
10. Director
CREATE TABLE `db_9ab8b7_6010`.`Director` ( `EMP_ID` VARCHAR(3) NOT NULL , `Name` VARCHAR(20)
NOT NULL , `Phone` INT(10) NOT NULL , `Address` TEXT NOT NULL , PRIMARY KEY (`Name`), INDEX
`EMP_ID` (`EMP_ID`)) ENGINE = InnoDB COMMENT = 'Director';
**Insert data**
INSERT INTO `Director` (`EMP_ID`, `Name`, `Phone`, `Address`) VALUES ('D01', 'Johanna', '0999999999',
'220 Spencer st\r\n'), ('D02', 'Joey', '0888888888', '34 Sydney rd\r\n'), ('D03', 'Bob', '0777777777', '8 Boruk
st\r\n'), ('D04', 'Arun', '0666666666', '90 Queen st\r\n'), ('D05', 'TJ', '0555555555', '67 Bridge rd\r\n');
**Create table**
11. Music VDO
CREATE TABLE `db_9ab8b7_6010`.`MusicVDO` ( `VDO_id` VARCHAR(3) NOT NULL , `Title` TEXT NOT
NULL , `Length` VARCHAR(10) NOT NULL , `Location` TEXT NOT NULL , `IdSong` VARCHAR(3) NOT NULL ,
PRIMARY KEY (`VDO_id`), INDEX `IdSong` (`IdSong`)) ENGINE = InnoDB COMMENT = 'MusicVDO';
**Insert data**
INSERT INTO `MusicVDO` (`VDO_id`, `Title`, `Length`, `Location`, `IdSong`) VALUES ('V01', 'Felling down\r\n',
'3.9 mins', 'Japan', 'S01'), ('V02', 'Just close your eyes\r\n', '2.9 mins ', 'Mynmar', 'S02'), ('V03', 'Bring me the
tear\r\n', '3.0 mins ', 'Singapore', 'S03'), ('V04', 'Happiness around me\r\n', '3.4 mins ', 'London',
'S04'), ('V05', 'My life\r\n', '2.5 mins', 'Hong Kong ', 'S05');
**Create table**
12. Accountant
CREATE TABLE `db_9ab8b7_6010`.`Accountant` ( `EMP_ID` VARCHAR(3) NOT NULL , `Name`
VARCHAR(20) NOT NULL , `Phone` INT(10) NOT NULL , `Address` TEXT NOT NULL , `Cert` BOOLEAN NOT
NULL , PRIMARY KEY (`Name`), INDEX `EMP_ID` (`EMP_ID`)) ENGINE = InnoDB COMMENT = 'Accountant';
**Insert data**
INSERT INTO `Accountant` (`EMP_ID`, `Name`, `Phone`, `Address`, `Cert`) VALUES ('C01', 'Lala',
'0456738293', '899 Russell rd \r\n', TEXT('Yes')), ('C02', 'Paula', '0457783928', '1 king st\r\n', TEXT('Yes')),
('C03', 'Roy', '0489203349', '32/12 Spencer st\r\n', TEXT('Yes')), ('C04', 'Tailor', '0456273898', '55 Londale
st\r\n', TEXT('Yes')), ('C05', 'Ducklas', '0421326578', '9 Queen st \r\n', TEXT('Yes'));
**Create table**
13. Manager
CREATE TABLE `db_9ab8b7_6010`.`Manager` ( `EMP_ID` VARCHAR(3) NOT NULL , `Name` VARCHAR(20)
NOT NULL , `Phone` INT(10) NOT NULL , `Address` TEXT NOT NULL , `ManageEmp` TEXT NOT NULL ,
`OwnCar` TEXT NOT NULL , PRIMARY KEY (`Name`), INDEX `EMP_ID` (`EMP_ID`)) ENGINE = InnoDB
COMMENT = 'Manager';
**Insert data**
INSERT INTO `Manager` (`EMP_ID`, `Name`, `Phone`, `Address`, `ManageEmp`, `OwnCar`) VALUES ('M01',
'Jin', '0412345678', '1 William st\r\n', 'Yes', 'Yes'), ('M02', 'Aya', '0423456789', '12 Elwood ave\r\n', 'Yes', 'Yes'),
('M03', 'Kim', '0434567890', '3 Dockland\r\n', 'Yes', 'Yes'), ('M04', 'Clark', '0445678901', '45 King st\r\n', 'Yes',
'Yes'), ('M05', 'Pink', '0456789012', '2 Swanston st\r\n', 'Yes', 'Yes');
Completed table
Delete / Update / Alter
1. Employee
5. Count the number of artist, the name of the record company they are assigned to, make sure to
display the counts for each record company.
SELECT CompanyName, COUNT(Name) AS Artist
FROM musician
GROUP BY CompanyName
6. List all the incoming future tours (starting from June 2017).
SELECT * FROM `concert`
WHERE Date > "2017-06-01"
7. List the cities that have had concerts in them(display each city name once - no duplications are
allowed).
SELECT country FROM concert
WHERE Date < "2017-06-01"
8. Find the minimum price of an album, display it with the album name.
SELECT * FROM `album`
WHERE Price = (SELECT MIN(Price) FROM album)
9. Find the maximum price of an album display it with the album name.
SELECT * FROM `album`
WHERE Price = (SELECT MAX(Price) FROM album)