Sunteți pe pagina 1din 25

mysql> use hamu;

Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table tracks(


-> track_id int primary key,
-> artist_id int,
-> tname varchar(255),
-> length int,
-> foreign key(artist_id) references artists(artist_id)
-> );
ERROR 1215 (HY000): Cannot add foreign key constraint
mysql> create table artists(
-> artist_id int primary key,
-> sname varchar(255),
-> location varchar(255)
-> );
Query OK, 0 rows affected (0.44 sec)

mysql> create table tracks(


-> track_id int primary key,
-> artist_id int,
-> tname varchar(255),
-> length int,
-> foreign key(artist_id) references artists(artist_id)
-> );
Query OK, 0 rows affected (0.52 sec)

mysql>
mysql> insert into artists(artist_id,sname,location)
-> values(1001,'Alla Rakha Rehman','Chennai'),
-> (1002,'Kailas Kher','Delhi'),
-> (1003,'Rahul Dev Barman','Kolkata'),
-> (1004,'Lucky Ali','Mumbai');
Query OK, 4 rows affected (0.14 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> insert into tracks(track_id,artist_id,tname,length)


-> values(10,1001,'Bande Matram',6),
-> (11,1002,'Alla Ke Bande',10),
-> (12,1003,'Raste Apni Jagah',12),
-> (13,1003,'Kahi Door Jab',5),
-> (14,1001,'Maa Tujhe Salaam',8),
-> (15,1002,'Teri Dewani',6),
-> (16,1003,'Ak Rasta Hai',7);
Query OK, 7 rows affected (0.11 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from artists;


+-----------+-------------------+----------+
| artist_id | sname | location |
+-----------+-------------------+----------+
| 1001 | Alla Rakha Rehman | Chennai |
| 1002 | Kailas Kher | Delhi |
| 1003 | Rahul Dev Barman | Kolkata |
| 1004 | Lucky Ali | Mumbai |
+-----------+-------------------+----------+
4 rows in set (0.00 sec)

mysql> select * from tracks;


+----------+-----------+------------------+--------+
| track_id | artist_id | tname | length |
+----------+-----------+------------------+--------+
| 10 | 1001 | Bande Matram | 6 |
| 11 | 1002 | Alla Ke Bande | 10 |
| 12 | 1003 | Raste Apni Jagah | 12 |
| 13 | 1003 | Kahi Door Jab | 5 |
| 14 | 1001 | Maa Tujhe Salaam | 8 |
| 15 | 1002 | Teri Dewani | 6 |
| 16 | 1003 | Ak Rasta Hai | 7 |
+----------+-----------+------------------+--------+
7 rows in set (0.00 sec)

mysql> create table emp(


-> eid int primary key,
-> ename varchar(255),
-> age int,
-> salary int
-> );
Query OK, 0 rows affected (0.47 sec)

mysql>
mysql>
mysql> create table dept(
-> did int primary key,
-> dname varchar(255),
-> budget int,
-> managerid int
-> );
Query OK, 0 rows affected (0.52 sec)

mysql> create table works(


-> eid int,
-> did int,
-> pct_time int,
-> foreign key(eid) references emp(eid),
-> foreign key(did) references dept(did)
-> );
Query OK, 0 rows affected (0.44 sec)

mysql>
mysql> insert into emp(eid,ename,age,salary)
-> values(1001,'Sabeer Bhatia',60,50000),
-> (1002,'Pranav Mistry',65,55000),
-> (1003,'Sam Pitroda',50,60000),
-> (1004,'Mark Zuckerberg',50,35000),
-> (1005,'Larry Page',40,45000),
-> (1006,'Steve Ballmer',45,46000),
-> (1007,'Tim Cook',80,65000);
Query OK, 7 rows affected (0.08 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> insert into dept(did,dname,budget,managerid)


-> values(10,'Hardware',10000,1001),
-> (20,'Software',20000,1002),
-> (30,'Quality Assurance',30000,1003),
-> (40,'Development',15000,1004),
-> (50,'Human Resources',40000,1005),
-> (60,'Support',12000,1006);
Query OK, 6 rows affected (0.11 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into works(eid,did,pct_time)


-> values(1001,10,20),
-> (1002,20,30),
-> (1004,40,15),
-> (1005,40,50),
-> (1003,30,80),
-> (1006,60,35),
-> (1005,50,40),
-> (1001,20,15);
Query OK, 8 rows affected (0.30 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> select
-> * from emp;
+------+-----------------+------+--------+
| eid | ename | age | salary |
+------+-----------------+------+--------+
| 1001 | Sabeer Bhatia | 60 | 50000 |
| 1002 | Pranav Mistry | 65 | 55000 |
| 1003 | Sam Pitroda | 50 | 60000 |
| 1004 | Mark Zuckerberg | 50 | 35000 |
| 1005 | Larry Page | 40 | 45000 |
| 1006 | Steve Ballmer | 45 | 46000 |
| 1007 | Tim Cook | 80 | 65000 |
+------+-----------------+------+--------+
7 rows in set (0.00 sec)

mysql> select * from dept;


+-----+-------------------+--------+-----------+
| did | dname | budget | managerid |
+-----+-------------------+--------+-----------+
| 10 | Hardware | 10000 | 1001 |
| 20 | Software | 20000 | 1002 |
| 30 | Quality Assurance | 30000 | 1003 |
| 40 | Development | 15000 | 1004 |
| 50 | Human Resources | 40000 | 1005 |
| 60 | Support | 12000 | 1006 |
+-----+-------------------+--------+-----------+
6 rows in set (0.00 sec)

mysql> select *from works;


+------+------+----------+
| eid | did | pct_time |
+------+------+----------+
| 1001 | 10 | 20 |
| 1002 | 20 | 30 |
| 1004 | 40 | 15 |
| 1005 | 40 | 50 |
| 1003 | 30 | 80 |
| 1006 | 60 | 35 |
| 1005 | 50 | 40 |
| 1001 | 20 | 15 |
+------+------+----------+
8 rows in set (0.00 sec)

mysql> create table suppliers(


-> sid int primary key,
-> sname varchar(255),
-> scity varchar(255)
-> );
Query OK, 0 rows affected (0.67 sec)

mysql> create table parts(


-> pid int primary key,
-> pname varchar(255),
-> color varchar(255)
-> );
Query OK, 0 rows affected (0.30 sec)

mysql>
mysql> create table catalog(
-> sid int,
-> pid int,
-> price int,
-> foreign key(sid) references suppliers(sid),
-> foreign key(pid) references parts(pid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> insert into suppliers(sid,sname,scity)


-> values(1001,'Tata','Delhi'),
-> (1002,'Toyota','Tokyo'),
-> (1003,'Maruti','Fukishima'),
-> (1004,'Ford','Detroit'),
-> (1005,'Chevrolet','New York'),
-> (1006,'Nissan','Hiroshima'),
-> (1007,'Renault','Paris'),
-> (1008,'Mahindra','Pune');
Query OK, 8 rows affected (0.09 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> insert into parts(pid,pname,color)


-> values(11,'Wind Shield Wiper','Red'),
-> (12,'Alloy Wheel','Green'),
-> (13,'Steering','Red'),
-> (14,'Tyre','Black'),
-> (15,'Handle','Green');
Query OK, 5 rows affected (0.13 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> insert into catalog(sid,pid,price)


-> values(1001,11,20000),
-> (1002,11,30000),
-> (1003,11,25000),
-> (1004,12,22000),
-> (1004,13,21000),
-> (1004,14,40000),
-> (1005,12,33000),
-> (1008,13,44000),
-> (1007,14,11000);
Query OK, 9 rows affected (0.17 sec)
Records: 9 Duplicates: 0 Warnings: 0
mysql> select * from supliers;
ERROR 1146 (42S02): Table 'hamu.supliers' doesn't exist
mysql> select * from suppliers;
+------+-----------+-----------+
| sid | sname | scity |
+------+-----------+-----------+
| 1001 | Tata | Delhi |
| 1002 | Toyota | Tokyo |
| 1003 | Maruti | Fukishima |
| 1004 | Ford | Detroit |
| 1005 | Chevrolet | New York |
| 1006 | Nissan | Hiroshima |
| 1007 | Renault | Paris |
| 1008 | Mahindra | Pune |
+------+-----------+-----------+
8 rows in set (0.00 sec)

mysql> select * from parts;


+-----+-------------------+-------+
| pid | pname | color |
+-----+-------------------+-------+
| 11 | Wind Shield Wiper | Red |
| 12 | Alloy Wheel | Green |
| 13 | Steering | Red |
| 14 | Tyre | Black |
| 15 | Handle | Green |
+-----+-------------------+-------+
5 rows in set (0.00 sec)

mysql> select * from catalog;


+------+------+-------+
| sid | pid | price |
+------+------+-------+
| 1001 | 11 | 20000 |
| 1002 | 11 | 30000 |
| 1003 | 11 | 25000 |
| 1004 | 12 | 22000 |
| 1004 | 13 | 21000 |
| 1004 | 14 | 40000 |
| 1005 | 12 | 33000 |
| 1008 | 13 | 44000 |
| 1007 | 14 | 11000 |
+------+------+-------+
9 rows in set (0.00 sec)

mysql> create table sailors(


-> sid int primary key,
-> sname varchar(255),
-> rating int,
-> age int
-> );
Query OK, 0 rows affected (0.38 sec)

mysql> create table boats(


-> bid int primary key,
-> bname varchar(255),
-> color varchar(255)
-> );
Query OK, 0 rows affected (0.43 sec)

mysql> create table reserves(


-> sid int,
-> bid int,
-> day int,
-> foreign key(sid) references sailors(sid),
-> foreign key(bid) references boats(bid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> insert into sailors(sid,sname,rating,age)


-> values(1001,'Jack Sparrow',8,34),
-> (1002,'William Nick',6,55),
-> (1003,'Columbus',3,45),
-> (1004,'Vasco D Gama',5,29),
-> (1005,'Magellan',9,51),
-> (1006,'Witwikcy',1,45);
Query OK, 6 rows affected (0.11 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into boats(bid,bname,color)


-> values(12,'INS Virat','Red'),
-> (13,'INS Arjun','Green'),
-> (14,'INS Kavery','Blue'),
-> (15,'INS Ajay','Green');
Query OK, 4 rows affected (0.13 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> insert into reserves(sid,bid,day)


-> values(1001,12,2),
-> (1001,13,2),
-> (1002,14,3),
-> (1002,15,4),
-> (1003,12,5),
-> (1004,12,6),
-> (1005,15,1);
Query OK, 7 rows affected (0.25 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql>
mysql> select * from reserves;
+------+------+------+
| sid | bid | day |
+------+------+------+
| 1001 | 12 | 2 |
| 1001 | 13 | 2 |
| 1002 | 14 | 3 |
| 1002 | 15 | 4 |
| 1003 | 12 | 5 |
| 1004 | 12 | 6 |
| 1005 | 15 | 1 |
+------+------+------+
7 rows in set (0.00 sec)

mysql> select* from sailers;


ERROR 1146 (42S02): Table 'hamu.sailers' doesn't exist
mysql> select* from sailors;
+------+--------------+--------+------+
| sid | sname | rating | age |
+------+--------------+--------+------+
| 1001 | Jack Sparrow | 8 | 34 |
| 1002 | William Nick | 6 | 55 |
| 1003 | Columbus | 3 | 45 |
| 1004 | Vasco D Gama | 5 | 29 |
| 1005 | Magellan | 9 | 51 |
| 1006 | Witwikcy | 1 | 45 |
+------+--------------+--------+------+
6 rows in set (0.00 sec)

mysql> select* from boats;


+-----+------------+-------+
| bid | bname | color |
+-----+------------+-------+
| 12 | INS Virat | Red |
| 13 | INS Arjun | Green |
| 14 | INS Kavery | Blue |
| 15 | INS Ajay | Green |
+-----+------------+-------+
4 rows in set (0.00 sec)

mysql> create table department(


-> deptid int primary key,
-> deptname varchar(255),
-> building varchar(255)
-> );
Query OK, 0 rows affected (0.48 sec)

mysql> create table professor(


-> profid int primary key,
-> deptid int,
-> profname varchar(255),
-> profage int,
-> salary int,
-> foreign key(deptid) references department(deptid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> mysql> Ctrl-C -- exit!


create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> );
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 'create
table committee(
commname varchar(255),
profid int,
foreign key(profid) r' at line 5
mysql> create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> );
Query OK, 0 rows affected (0.35 sec)

mysql> insert into department(deptid,deptname,building)


-> values(10,'Mathematics','White'),
-> (11,'Physics','Red'),
-> (12,'Computer Science','Green'),
-> (13,'Zoology','Black');
Query OK, 4 rows affected (0.12 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql>
mysql> insert into professor(profid,deptid,profname,profage,salary)
-> values(2222,10,'Santosh Kumar',45,45000),
-> (2223,11,'Sukumar',44,55000),
-> (2224,11,'Naveen Garg',34,65000),
-> (2225,12,'Bimal Roy',49,47000),
-> (2226,13,'Sia Bal Pal',39,48000),
-> (2227,12,'Pramod Kumar Kapoor',40,79000),
-> (2228,13,'Sandeep Sen',42,59000);
Query OK, 7 rows affected (0.11 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> insert into committee(commname,profid)


-> values('Course Structure',2222),
-> ('Examination',2223),
-> ('Examination',2224),
-> ('Mark Evaluation',2225),
-> ('Scholarship',2226),
-> ('Discipline',2227);
Query OK, 6 rows affected (0.13 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from committee;


+------------------+--------+
| commname | profid |
+------------------+--------+
| Course Structure | 2222 |
| Examination | 2223 |
| Examination | 2224 |
| Mark Evaluation | 2225 |
| Scholarship | 2226 |
| Discipline | 2227 |
+------------------+--------+
6 rows in set (0.00 sec)

mysql> select * from professor;


+--------+--------+---------------------+---------+--------+
| profid | deptid | profname | profage | salary |
+--------+--------+---------------------+---------+--------+
| 2222 | 10 | Santosh Kumar | 45 | 45000 |
| 2223 | 11 | Sukumar | 44 | 55000 |
| 2224 | 11 | Naveen Garg | 34 | 65000 |
| 2225 | 12 | Bimal Roy | 49 | 47000 |
| 2226 | 13 | Sia Bal Pal | 39 | 48000 |
| 2227 | 12 | Pramod Kumar Kapoor | 40 | 79000 |
| 2228 | 13 | Sandeep Sen | 42 | 59000 |
+--------+--------+---------------------+---------+--------+
7 rows in set (0.00 sec)
mysql> select * from department;
+--------+------------------+----------+
| deptid | deptname | building |
+--------+------------------+----------+
| 10 | Mathematics | White |
| 11 | Physics | Red |
| 12 | Computer Science | Green |
| 13 | Zoology | Black |
+--------+------------------+----------+
4 rows in set (0.00 sec)

mysql>
mysql>
mysql> create table pizza(
-> pid int primary key,
-> pname varchar(255),
-> size int
-> );
Query OK, 0 rows affected (0.61 sec)

mysql> create table store(


-> sname varchar(255) primary key,
-> location varchar(255),
-> Quality char(1)
-> );
Query OK, 0 rows affected (0.45 sec)

mysql> mysql> Ctrl-C -- exit!


create table soldby(
-> pid int,
-> sname varchar(255),
-> price int,
-> foreign key(pid) references pizza(pid),
-> foreign key(sname) references store(sname)
-> );
Query OK, 0 rows affected (0.41 sec)

mysql> insert into pizza(pid,pname,size)


-> values(101,'Domino',10),
-> (102,'Pizza Hut',20),
-> (103,'PSD',30),
-> (104,'Subway',25),
-> (105,'Mc Donald',30),
-> (106,'Nirullas',28);
Query OK, 6 rows affected (0.09 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into store(sname,location,quality)


-> values('Cannaught Place','Central Delhi','A'),
-> ('India Gate','Central Delhi','B'),
-> ('Saket','South Delhi','B'),
-> ('North Store','Civil Lines','C'),
-> ('South Store','Malviya Nagar','D');
Query OK, 5 rows affected (0.11 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> insert into soldby(pid,sname,price)


-> values(101,'Cannaught Place',100),
-> (102,'India Gate',200),
-> (101,'North Store',300),
-> (103,'South Store',450),
-> (104,'Saket',110),
-> (105,'North Store',150),
-> (101,'North Store',250);
Query OK, 7 rows affected (0.33 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from pizza;


+-----+-----------+------+
| pid | pname | size |
+-----+-----------+------+
| 101 | Domino | 10 |
| 102 | Pizza Hut | 20 |
| 103 | PSD | 30 |
| 104 | Subway | 25 |
| 105 | Mc Donald | 30 |
| 106 | Nirullas | 28 |
+-----+-----------+------+
6 rows in set (0.00 sec)

mysql> select
-> * from store;
+-----------------+---------------+---------+
| sname | location | Quality |
+-----------------+---------------+---------+
| Cannaught Place | Central Delhi | A |
| India Gate | Central Delhi | B |
| North Store | Civil Lines | C |
| Saket | South Delhi | B |
| South Store | Malviya Nagar | D |
+-----------------+---------------+---------+
5 rows in set (0.00 sec)

mysql> select * from soldby;


+------+-----------------+-------+
| pid | sname | price |
+------+-----------------+-------+
| 101 | Cannaught Place | 100 |
| 102 | India Gate | 200 |
| 101 | North Store | 300 |
| 103 | South Store | 450 |
| 104 | Saket | 110 |
| 105 | North Store | 150 |
| 101 | North Store | 250 |
+------+-----------------+-------+
7 rows in set (0.00 sec)

mysql>
mysql> use hamu;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table tracks(


-> track_id int primary key,
-> artist_id int,
-> tname varchar(255),
-> length int,
-> foreign key(artist_id) references artists(artist_id)
-> );
ERROR 1215 (HY000): Cannot add foreign key constraint
mysql> create table artists(
-> artist_id int primary key,
-> sname varchar(255),
-> location varchar(255)
-> );
Query OK, 0 rows affected (0.44 sec)

mysql> create table tracks(


-> track_id int primary key,
-> artist_id int,
-> tname varchar(255),
-> length int,
-> foreign key(artist_id) references artists(artist_id)
-> );
Query OK, 0 rows affected (0.52 sec)

mysql>
mysql> insert into artists(artist_id,sname,location)
-> values(1001,'Alla Rakha Rehman','Chennai'),
-> (1002,'Kailas Kher','Delhi'),
-> (1003,'Rahul Dev Barman','Kolkata'),
-> (1004,'Lucky Ali','Mumbai');
Query OK, 4 rows affected (0.14 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> insert into tracks(track_id,artist_id,tname,length)


-> values(10,1001,'Bande Matram',6),
-> (11,1002,'Alla Ke Bande',10),
-> (12,1003,'Raste Apni Jagah',12),
-> (13,1003,'Kahi Door Jab',5),
-> (14,1001,'Maa Tujhe Salaam',8),
-> (15,1002,'Teri Dewani',6),
-> (16,1003,'Ak Rasta Hai',7);
Query OK, 7 rows affected (0.11 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from artists;


+-----------+-------------------+----------+
| artist_id | sname | location |
+-----------+-------------------+----------+
| 1001 | Alla Rakha Rehman | Chennai |
| 1002 | Kailas Kher | Delhi |
| 1003 | Rahul Dev Barman | Kolkata |
| 1004 | Lucky Ali | Mumbai |
+-----------+-------------------+----------+
4 rows in set (0.00 sec)

mysql> select * from tracks;


+----------+-----------+------------------+--------+
| track_id | artist_id | tname | length |
+----------+-----------+------------------+--------+
| 10 | 1001 | Bande Matram | 6 |
| 11 | 1002 | Alla Ke Bande | 10 |
| 12 | 1003 | Raste Apni Jagah | 12 |
| 13 | 1003 | Kahi Door Jab | 5 |
| 14 | 1001 | Maa Tujhe Salaam | 8 |
| 15 | 1002 | Teri Dewani | 6 |
| 16 | 1003 | Ak Rasta Hai | 7 |
+----------+-----------+------------------+--------+
7 rows in set (0.00 sec)

mysql> create table emp(


-> eid int primary key,
-> ename varchar(255),
-> age int,
-> salary int
-> );
Query OK, 0 rows affected (0.47 sec)

mysql>
mysql>
mysql> create table dept(
-> did int primary key,
-> dname varchar(255),
-> budget int,
-> managerid int
-> );
Query OK, 0 rows affected (0.52 sec)

mysql> create table works(


-> eid int,
-> did int,
-> pct_time int,
-> foreign key(eid) references emp(eid),
-> foreign key(did) references dept(did)
-> );
Query OK, 0 rows affected (0.44 sec)

mysql>
mysql> insert into emp(eid,ename,age,salary)
-> values(1001,'Sabeer Bhatia',60,50000),
-> (1002,'Pranav Mistry',65,55000),
-> (1003,'Sam Pitroda',50,60000),
-> (1004,'Mark Zuckerberg',50,35000),
-> (1005,'Larry Page',40,45000),
-> (1006,'Steve Ballmer',45,46000),
-> (1007,'Tim Cook',80,65000);
Query OK, 7 rows affected (0.08 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> insert into dept(did,dname,budget,managerid)


-> values(10,'Hardware',10000,1001),
-> (20,'Software',20000,1002),
-> (30,'Quality Assurance',30000,1003),
-> (40,'Development',15000,1004),
-> (50,'Human Resources',40000,1005),
-> (60,'Support',12000,1006);
Query OK, 6 rows affected (0.11 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into works(eid,did,pct_time)


-> values(1001,10,20),
-> (1002,20,30),
-> (1004,40,15),
-> (1005,40,50),
-> (1003,30,80),
-> (1006,60,35),
-> (1005,50,40),
-> (1001,20,15);
Query OK, 8 rows affected (0.30 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> select
-> * from emp;
+------+-----------------+------+--------+
| eid | ename | age | salary |
+------+-----------------+------+--------+
| 1001 | Sabeer Bhatia | 60 | 50000 |
| 1002 | Pranav Mistry | 65 | 55000 |
| 1003 | Sam Pitroda | 50 | 60000 |
| 1004 | Mark Zuckerberg | 50 | 35000 |
| 1005 | Larry Page | 40 | 45000 |
| 1006 | Steve Ballmer | 45 | 46000 |
| 1007 | Tim Cook | 80 | 65000 |
+------+-----------------+------+--------+
7 rows in set (0.00 sec)

mysql> select * from dept;


+-----+-------------------+--------+-----------+
| did | dname | budget | managerid |
+-----+-------------------+--------+-----------+
| 10 | Hardware | 10000 | 1001 |
| 20 | Software | 20000 | 1002 |
| 30 | Quality Assurance | 30000 | 1003 |
| 40 | Development | 15000 | 1004 |
| 50 | Human Resources | 40000 | 1005 |
| 60 | Support | 12000 | 1006 |
+-----+-------------------+--------+-----------+
6 rows in set (0.00 sec)

mysql> select *from works;


+------+------+----------+
| eid | did | pct_time |
+------+------+----------+
| 1001 | 10 | 20 |
| 1002 | 20 | 30 |
| 1004 | 40 | 15 |
| 1005 | 40 | 50 |
| 1003 | 30 | 80 |
| 1006 | 60 | 35 |
| 1005 | 50 | 40 |
| 1001 | 20 | 15 |
+------+------+----------+
8 rows in set (0.00 sec)

mysql> create table suppliers(


-> sid int primary key,
-> sname varchar(255),
-> scity varchar(255)
-> );
Query OK, 0 rows affected (0.67 sec)

mysql> create table parts(


-> pid int primary key,
-> pname varchar(255),
-> color varchar(255)
-> );
Query OK, 0 rows affected (0.30 sec)

mysql>
mysql> create table catalog(
-> sid int,
-> pid int,
-> price int,
-> foreign key(sid) references suppliers(sid),
-> foreign key(pid) references parts(pid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> insert into suppliers(sid,sname,scity)


-> values(1001,'Tata','Delhi'),
-> (1002,'Toyota','Tokyo'),
-> (1003,'Maruti','Fukishima'),
-> (1004,'Ford','Detroit'),
-> (1005,'Chevrolet','New York'),
-> (1006,'Nissan','Hiroshima'),
-> (1007,'Renault','Paris'),
-> (1008,'Mahindra','Pune');
Query OK, 8 rows affected (0.09 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> insert into parts(pid,pname,color)


-> values(11,'Wind Shield Wiper','Red'),
-> (12,'Alloy Wheel','Green'),
-> (13,'Steering','Red'),
-> (14,'Tyre','Black'),
-> (15,'Handle','Green');
Query OK, 5 rows affected (0.13 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> insert into catalog(sid,pid,price)


-> values(1001,11,20000),
-> (1002,11,30000),
-> (1003,11,25000),
-> (1004,12,22000),
-> (1004,13,21000),
-> (1004,14,40000),
-> (1005,12,33000),
-> (1008,13,44000),
-> (1007,14,11000);
Query OK, 9 rows affected (0.17 sec)
Records: 9 Duplicates: 0 Warnings: 0

mysql> select * from supliers;


ERROR 1146 (42S02): Table 'hamu.supliers' doesn't exist
mysql> select * from suppliers;
+------+-----------+-----------+
| sid | sname | scity |
+------+-----------+-----------+
| 1001 | Tata | Delhi |
| 1002 | Toyota | Tokyo |
| 1003 | Maruti | Fukishima |
| 1004 | Ford | Detroit |
| 1005 | Chevrolet | New York |
| 1006 | Nissan | Hiroshima |
| 1007 | Renault | Paris |
| 1008 | Mahindra | Pune |
+------+-----------+-----------+
8 rows in set (0.00 sec)

mysql> select * from parts;


+-----+-------------------+-------+
| pid | pname | color |
+-----+-------------------+-------+
| 11 | Wind Shield Wiper | Red |
| 12 | Alloy Wheel | Green |
| 13 | Steering | Red |
| 14 | Tyre | Black |
| 15 | Handle | Green |
+-----+-------------------+-------+
5 rows in set (0.00 sec)

mysql> select * from catalog;


+------+------+-------+
| sid | pid | price |
+------+------+-------+
| 1001 | 11 | 20000 |
| 1002 | 11 | 30000 |
| 1003 | 11 | 25000 |
| 1004 | 12 | 22000 |
| 1004 | 13 | 21000 |
| 1004 | 14 | 40000 |
| 1005 | 12 | 33000 |
| 1008 | 13 | 44000 |
| 1007 | 14 | 11000 |
+------+------+-------+
9 rows in set (0.00 sec)

mysql> create table sailors(


-> sid int primary key,
-> sname varchar(255),
-> rating int,
-> age int
-> );
Query OK, 0 rows affected (0.38 sec)

mysql> create table boats(


-> bid int primary key,
-> bname varchar(255),
-> color varchar(255)
-> );
Query OK, 0 rows affected (0.43 sec)

mysql> create table reserves(


-> sid int,
-> bid int,
-> day int,
-> foreign key(sid) references sailors(sid),
-> foreign key(bid) references boats(bid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> insert into sailors(sid,sname,rating,age)


-> values(1001,'Jack Sparrow',8,34),
-> (1002,'William Nick',6,55),
-> (1003,'Columbus',3,45),
-> (1004,'Vasco D Gama',5,29),
-> (1005,'Magellan',9,51),
-> (1006,'Witwikcy',1,45);
Query OK, 6 rows affected (0.11 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into boats(bid,bname,color)


-> values(12,'INS Virat','Red'),
-> (13,'INS Arjun','Green'),
-> (14,'INS Kavery','Blue'),
-> (15,'INS Ajay','Green');
Query OK, 4 rows affected (0.13 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> insert into reserves(sid,bid,day)


-> values(1001,12,2),
-> (1001,13,2),
-> (1002,14,3),
-> (1002,15,4),
-> (1003,12,5),
-> (1004,12,6),
-> (1005,15,1);
Query OK, 7 rows affected (0.25 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql>
mysql> select * from reserves;
+------+------+------+
| sid | bid | day |
+------+------+------+
| 1001 | 12 | 2 |
| 1001 | 13 | 2 |
| 1002 | 14 | 3 |
| 1002 | 15 | 4 |
| 1003 | 12 | 5 |
| 1004 | 12 | 6 |
| 1005 | 15 | 1 |
+------+------+------+
7 rows in set (0.00 sec)

mysql> select* from sailers;


ERROR 1146 (42S02): Table 'hamu.sailers' doesn't exist
mysql> select* from sailors;
+------+--------------+--------+------+
| sid | sname | rating | age |
+------+--------------+--------+------+
| 1001 | Jack Sparrow | 8 | 34 |
| 1002 | William Nick | 6 | 55 |
| 1003 | Columbus | 3 | 45 |
| 1004 | Vasco D Gama | 5 | 29 |
| 1005 | Magellan | 9 | 51 |
| 1006 | Witwikcy | 1 | 45 |
+------+--------------+--------+------+
6 rows in set (0.00 sec)

mysql> select* from boats;


+-----+------------+-------+
| bid | bname | color |
+-----+------------+-------+
| 12 | INS Virat | Red |
| 13 | INS Arjun | Green |
| 14 | INS Kavery | Blue |
| 15 | INS Ajay | Green |
+-----+------------+-------+
4 rows in set (0.00 sec)

mysql> create table department(


-> deptid int primary key,
-> deptname varchar(255),
-> building varchar(255)
-> );
Query OK, 0 rows affected (0.48 sec)

mysql> create table professor(


-> profid int primary key,
-> deptid int,
-> profname varchar(255),
-> profage int,
-> salary int,
-> foreign key(deptid) references department(deptid)
-> );
Query OK, 0 rows affected (0.56 sec)

mysql> mysql> Ctrl-C -- exit!


create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> );
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 'create
table committee(
commname varchar(255),
profid int,
foreign key(profid) r' at line 5
mysql> create table committee(
-> commname varchar(255),
-> profid int,
-> foreign key(profid) references professor(profid)
-> );
Query OK, 0 rows affected (0.35 sec)

mysql> insert into department(deptid,deptname,building)


-> values(10,'Mathematics','White'),
-> (11,'Physics','Red'),
-> (12,'Computer Science','Green'),
-> (13,'Zoology','Black');
Query OK, 4 rows affected (0.12 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql>
mysql> insert into professor(profid,deptid,profname,profage,salary)
-> values(2222,10,'Santosh Kumar',45,45000),
-> (2223,11,'Sukumar',44,55000),
-> (2224,11,'Naveen Garg',34,65000),
-> (2225,12,'Bimal Roy',49,47000),
-> (2226,13,'Sia Bal Pal',39,48000),
-> (2227,12,'Pramod Kumar Kapoor',40,79000),
-> (2228,13,'Sandeep Sen',42,59000);
Query OK, 7 rows affected (0.11 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> insert into committee(commname,profid)


-> values('Course Structure',2222),
-> ('Examination',2223),
-> ('Examination',2224),
-> ('Mark Evaluation',2225),
-> ('Scholarship',2226),
-> ('Discipline',2227);
Query OK, 6 rows affected (0.13 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from committee;


+------------------+--------+
| commname | profid |
+------------------+--------+
| Course Structure | 2222 |
| Examination | 2223 |
| Examination | 2224 |
| Mark Evaluation | 2225 |
| Scholarship | 2226 |
| Discipline | 2227 |
+------------------+--------+
6 rows in set (0.00 sec)

mysql> select * from professor;


+--------+--------+---------------------+---------+--------+
| profid | deptid | profname | profage | salary |
+--------+--------+---------------------+---------+--------+
| 2222 | 10 | Santosh Kumar | 45 | 45000 |
| 2223 | 11 | Sukumar | 44 | 55000 |
| 2224 | 11 | Naveen Garg | 34 | 65000 |
| 2225 | 12 | Bimal Roy | 49 | 47000 |
| 2226 | 13 | Sia Bal Pal | 39 | 48000 |
| 2227 | 12 | Pramod Kumar Kapoor | 40 | 79000 |
| 2228 | 13 | Sandeep Sen | 42 | 59000 |
+--------+--------+---------------------+---------+--------+
7 rows in set (0.00 sec)

mysql> select * from department;


+--------+------------------+----------+
| deptid | deptname | building |
+--------+------------------+----------+
| 10 | Mathematics | White |
| 11 | Physics | Red |
| 12 | Computer Science | Green |
| 13 | Zoology | Black |
+--------+------------------+----------+
4 rows in set (0.00 sec)

mysql>
mysql>
mysql> create table pizza(
-> pid int primary key,
-> pname varchar(255),
-> size int
-> );
Query OK, 0 rows affected (0.61 sec)

mysql> create table store(


-> sname varchar(255) primary key,
-> location varchar(255),
-> Quality char(1)
-> );
Query OK, 0 rows affected (0.45 sec)

mysql> mysql> Ctrl-C -- exit!


create table soldby(
-> pid int,
-> sname varchar(255),
-> price int,
-> foreign key(pid) references pizza(pid),
-> foreign key(sname) references store(sname)
-> );
Query OK, 0 rows affected (0.41 sec)

mysql> insert into pizza(pid,pname,size)


-> values(101,'Domino',10),
-> (102,'Pizza Hut',20),
-> (103,'PSD',30),
-> (104,'Subway',25),
-> (105,'Mc Donald',30),
-> (106,'Nirullas',28);
Query OK, 6 rows affected (0.09 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> insert into store(sname,location,quality)


-> values('Cannaught Place','Central Delhi','A'),
-> ('India Gate','Central Delhi','B'),
-> ('Saket','South Delhi','B'),
-> ('North Store','Civil Lines','C'),
-> ('South Store','Malviya Nagar','D');
Query OK, 5 rows affected (0.11 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> insert into soldby(pid,sname,price)


-> values(101,'Cannaught Place',100),
-> (102,'India Gate',200),
-> (101,'North Store',300),
-> (103,'South Store',450),
-> (104,'Saket',110),
-> (105,'North Store',150),
-> (101,'North Store',250);
Query OK, 7 rows affected (0.33 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from pizza;


+-----+-----------+------+
| pid | pname | size |
+-----+-----------+------+
| 101 | Domino | 10 |
| 102 | Pizza Hut | 20 |
| 103 | PSD | 30 |
| 104 | Subway | 25 |
| 105 | Mc Donald | 30 |
| 106 | Nirullas | 28 |
+-----+-----------+------+
6 rows in set (0.00 sec)

mysql> select
-> * from store;
+-----------------+---------------+---------+
| sname | location | Quality |
+-----------------+---------------+---------+
| Cannaught Place | Central Delhi | A |
| India Gate | Central Delhi | B |
| North Store | Civil Lines | C |
| Saket | South Delhi | B |
| South Store | Malviya Nagar | D |
+-----------------+---------------+---------+
5 rows in set (0.00 sec)

mysql> select * from soldby;


+------+-----------------+-------+
| pid | sname | price |
+------+-----------------+-------+
| 101 | Cannaught Place | 100 |
| 102 | India Gate | 200 |
| 101 | North Store | 300 |
| 103 | South Store | 450 |
| 104 | Saket | 110 |
| 105 | North Store | 150 |
| 101 | North Store | 250 |
+------+-----------------+-------+
7 rows in set (0.00 sec)

mysql>
mysql> use hamu;
Database changed
mysql> select pname from pizza where pname like'__i%';
Empty set (0.00 sec)

mysql>
mysql> select pname from pizza where pname like'__i%';
Empty set (0.00 sec)

mysql>
mysql> select * from pizza;
+-----+-----------+------+
| pid | pname | size |
+-----+-----------+------+
| 101 | Domino | 10 |
| 102 | Pizza Hut | 20 |
| 103 | PSD | 30 |
| 104 | Subway | 25 |
| 105 | Mc Donald | 30 |
| 106 | Nirullas | 28 |
+-----+-----------+------+
6 rows in set (0.00 sec)

mysql> select pname from pizza where pname like'_i%';


+-----------+
| pname |
+-----------+
| Pizza Hut |
| Nirullas |
+-----------+
2 rows in set (0.00 sec)

mysql>
mysql> select pname from pizza where pid=(select pid from soldby group by pid order
by count(pid) desc limit 1);
+--------+
| pname |
+--------+
| Domino |
+--------+
1 row in set (0.06 sec)

mysql> select store.quality,avg(soldby.price) as 'average price' from store left


join soldby on store.sname=soldby.sname group by store.quality;
+---------+---------------+
| quality | average price |
+---------+---------------+
| A | 100.0000 |
| B | 155.0000 |
| C | 233.3333 |
| D | 450.0000 |
+---------+---------------+
4 rows in set (0.06 sec)

mysql>
mysql> select pname from pizza where pid not in (select pid from soldby);
+----------+
| pname |
+----------+
| Nirullas |
+----------+
1 row in set (0.02 sec)

mysql> select pname from pizza where pid in(select pid from soldby where
sname='north store');
+-----------+
| pname |
+-----------+
| Domino |
| Mc Donald |
+-----------+

mysql>
mysql> select pname from pizza where pid not in (select pid from soldby);
+----------+
| pname |
+----------+
| Nirullas |
+----------+
1 row in set (0.02 sec)

mysql> select pname from pizza where pid in(select pid from soldby where
sname='north store');
+-----------+
| pname |
+-----------+
| Domino |
| Mc Donald |
+-----------+
2 rows in set (0.06 sec)

mysql> select pname from pizza where pname='__i%';


Empty set (0.00 sec)
mysql> select pname from where pid=( select max(soldby) from soldby);
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 'where
pid=( select max(soldby) from soldby)' at line 1
mysql> select pname from where pid=( select max(soldby) from soldby);
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 'where
pid=( select max(soldby) from soldby)' at line 1
mysql> select pname from where pid=( select max(price) from soldby);
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 'where
pid=( select max(price) from soldby)' at line 1
mysql> select pname from pizza where pid=( select max(price) from soldby);
Empty set (0.00 sec)

mysql> select pname from pizza where pid=(select pid from soldby group by pid order
by count(pid) desc limit 1);
+--------+
| pname |
+--------+
| Domino |
+--------+
1 row in set (0.00 sec)

mysql> select pname from pizza where pid is not in ( select pid from soldby);
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 'in
( select pid from soldby)' at line 1
mysql> select pname from pizza where pid not in ( select pid from soldby);
+----------+
| pname |
+----------+
| Nirullas |
+----------+
1 row in set (0.00 sec)

mysql> select pname from pizza where pid in ( select pid from soldby where
sname='north store');
+-----------+
| pname |
+-----------+
| Domino |
| Mc Donald |
+-----------+
2 rows in set (0.00 sec)

mysql> select avg(price) as avg_price from soldby;


+-----------+
| avg_price |
+-----------+
| 222.8571 |
+-----------+
1 row in set (0.00 sec)

mysql>

S-ar putea să vă placă și