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

DBMS

Uploaded by

ompatil0251
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

DBMS

Uploaded by

ompatil0251
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Enter password: **********

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 10
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use world;


Database changed
mysql> create table employee4(emp_id int primary key,emp_name
varchar(20),emp_salary decimal(10,5),address varchar(20));
Query OK, 0 rows affected (0.05 sec)

mysql> describe employee4;


+------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+-------+
| emp_id | int | NO | PRI | NULL | |
| emp_name | varchar(20) | YES | | NULL | |
| emp_salary | decimal(10,5) | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
+------------+---------------+------+-----+---------+-------+
4 rows in set (0.03 sec)

mysql> create table fee(fee_id in primary key,fee_date date, fee_status


varchar(20));
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
primary key,fee_date date, fee_status varchar(20))' at line 1
mysql> ^C
mysql> create table fee(fee_id int primary key,fee_date date, fee_status
varchar(20));
Query OK, 0 rows affected (0.02 sec)

mysql> describe fee;


+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| fee_id | int | NO | PRI | NULL | |
| fee_date | date | YES | | NULL | |
| fee_status | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> create table furniture(fur_id int primary key,fur_type varchar(20));


Query OK, 0 rows affected (0.02 sec)

mysql> describe furniture;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| fur_id | int | NO | PRI | NULL | |
| fur_type | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> create table hostel(hos_id int primary key,hos_name varchar(20),hos_address


varchar(20),hos_rooms int ,hos_students int);
Query OK, 0 rows affected (0.02 sec)

mysql> describe hostel;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| hos_id | int | NO | PRI | NULL | |
| hos_name | varchar(20) | YES | | NULL | |
| hos_address | varchar(20) | YES | | NULL | |
| hos_rooms | int | YES | | NULL | |
| hos_students | int | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> create table room(room_id int primary key, capacity int);


Query OK, 0 rows affected (0.02 sec)

mysql> describe room;


+----------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| room_id | int | NO | PRI | NULL | |
| capacity | int | YES | | NULL | |
+----------+------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> create table student(stu_id int primary key,stu_name varchar(20),stu_address


varchar(20),age int);
ERROR 1050 (42S01): Table 'student' already exists
mysql> create table student4(stu_id int primary key,stu_name varchar(20),stu
_address varchar(20),age int);
Query OK, 0 rows affected (0.02 sec)

mysql> describe table student4;


+----+-------------+----------+------------+------+---------------+------+---------
+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len
| ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+---------------+------+---------
+------+------+----------+-------+
| 1 | SIMPLE | student4 | NULL | ALL | NULL | NULL | NULL
| NULL | 1 | 100.00 | NULL |
+----+-------------+----------+------------+------+---------------+------+---------
+------+------+----------+-------+
1 row in set, 1 warning (0.01 sec)

mysql> describe student4;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| stu_id | int | NO | PRI | NULL | |
| stu_name | varchar(20) | YES | | NULL | |
| stu_address | varchar(20) | YES | | NULL | |
| age | int | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table hostel add foreign key ()


alter table hostel add foreign key ()
describe student4;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| stu_id | int | NO | PRI | NULL | |
| stu_name | varchar(20) | YES | | NULL | |
| stu_address | varchar(20) | YES | | NULL | |
| age | int | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table hostel add column ep_id int;


Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table hostel add column rm_id int;


Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table hostel add foreign key(ep_id) references employee4(emp_id)


;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table hostel add foreign key(rm_id) references room(room_id);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table room add column furni_id int;


Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table room add column stud_id int;


Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table room add foreign key(furni_id) references furniture(fur_id


);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table room add foreign key(stud_id) references student4(stu_id);

Query OK, 0 rows affected (0.05 sec)


Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table fee add column stud_id int;


Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table fee add foreign key(stud_id) references student4(stu_id);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe hostel
-> ;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| hos_id | int | NO | PRI | NULL | |
| hos_name | varchar(20) | YES | | NULL | |
| hos_address | varchar(20) | YES | | NULL | |
| hos_rooms | int | YES | | NULL | |
| hos_students | int | YES | | NULL | |
| ep_id | int | YES | MUL | NULL | |
| rm_id | int | YES | MUL | NULL | |
+--------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> describe room;


+----------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| room_id | int | NO | PRI | NULL | |
| capacity | int | YES | | NULL | |
| furni_id | int | YES | MUL | NULL | |
| stud_id | int | YES | MUL | NULL | |
+----------+------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> describe fee;


+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| fee_id | int | NO | PRI | NULL | |
| fee_date | date | YES | | NULL | |
| fee_status | varchar(20) | YES | | NULL | |
| stud_id | int | YES | MUL | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into employee4 values(1,"OM",10000.00,"MUMBAI");


Query OK, 1 row affected (0.01 sec)

mysql> insert into employee4 values(2,"HEER",10001.00,"MANJARI");


Query OK, 1 row affected (0.00 sec)

mysql> insert into employee4 values(2,"HEET",10002.00,"MANJARI");


ERROR 1062 (23000): Duplicate entry '2' for key 'employee4.PRIMARY'
mysql> insert into employee4 values(3,"HEET",10002.00,"MANJARI");
Query OK, 1 row affected (0.01 sec)

mysql> insert into employee4 values(4,"OMKAR",10003.00,"PUNE");


Query OK, 1 row affected (0.01 sec)

mysql> insert into employee4 values(5,"SACHIN",10004.00,"LATUR");


Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM EMPOYEE4;


ERROR 1146 (42S02): Table 'world.empoyee4' doesn't exist
mysql> SELECT * FROM EMPLOYEE4;
+--------+----------+-------------+---------+
| emp_id | emp_name | emp_salary | address |
+--------+----------+-------------+---------+
| 1 | OM | 10000.00000 | MUMBAI |
| 2 | HEER | 10001.00000 | MANJARI |
| 3 | HEET | 10002.00000 | MANJARI |
| 4 | OMKAR | 10003.00000 | PUNE |
| 5 | SACHIN | 10004.00000 | LATUR |
+--------+----------+-------------+---------+
5 rows in set (0.00 sec)

mysql> insert into HOSTEL values(1,"ANUJA-1","LONI_KALBOR",20,80,,1,1);


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 ',1,1)'
at line 1
mysql> insert into HOSTEL values(1,"ANUJA-1","LONI_KALBOR",20,80,1,1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`world`.`hostel`, CONSTRAINT `hostel_ibfk_2` FOREIGN KEY (`rm_id`)
REFERENCES `room` (`room_id`))
mysql> insert into employee4 values(4,"OMKAR",10003.00,"PUNE");
ERROR 1062 (23000): Duplicate entry '4' for key 'employee4.PRIMARY'
mysql> insert into FEE values(1,'2024-10-22',"PAID");
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into STUDENT values(1,"SUYASH","NAGPUR",21);
ERROR 1366 (HY000): Incorrect decimal value: 'NAGPUR' for column 'percentage' at
row 1
mysql> insert into STUDENT4 values(1,"SUYASH","NAGPUR",21);
Query OK, 1 row affected (0.01 sec)

mysql> insert into STUDENT4 values(2,"SACHIN","LATUR",19);


Query OK, 1 row affected (0.01 sec)

mysql> insert into STUDENT4 values(3,"SHANTANU","PUNE",19);


Query OK, 1 row affected (0.01 sec)

mysql> insert into STUDENT4 values(4,"SUNNY","PUNE",19);


Query OK, 1 row affected (0.01 sec)

mysql> insert into STUDENT4 values(5,"OM","MUMBAI",20);


Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM STUDENT2;


+---------+------------+--------+------------+
| roll_no | name | city | percentage |
+---------+------------+--------+------------+
| 1 | Om Patil | Mumbai | 90.00000 |
| 3 | Harpalsing | Dhule | 92.00000 |
| 5 | Sachin | Latur | 90.00000 |
| 7 | Jishnu | Surat | 50.00000 |
+---------+------------+--------+------------+
4 rows in set (0.01 sec)

mysql> SELECT * FROM STUDENT4;


+--------+----------+-------------+------+
| stu_id | stu_name | stu_address | age |
+--------+----------+-------------+------+
| 1 | SUYASH | NAGPUR | 21 |
| 2 | SACHIN | LATUR | 19 |
| 3 | SHANTANU | PUNE | 19 |
| 4 | SUNNY | PUNE | 19 |
| 5 | OM | MUMBAI | 20 |
+--------+----------+-------------+------+
5 rows in set (0.00 sec)

mysql> insert into FEE values(1,"2024-10-22","PAID",20,2);


ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into FEE values(1,"2024-10-22","PAID",2);
Query OK, 1 row affected (0.01 sec)

mysql> insert into FEE values(2,"2024-10-22","PAID",1);


Query OK, 1 row affected (0.01 sec)

mysql> insert into FEE values(3,"2024-10-22","NOT-PAID",5);


Query OK, 1 row affected (0.01 sec)

mysql> insert into FEE values(4,"2024-10-22","NOT-PAID",3);


Query OK, 1 row affected (0.01 sec)

mysql> insert into FEE values(5,"2024-10-22","NOT-PAID",4);


Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM FEE;


+--------+------------+------------+---------+
| fee_id | fee_date | fee_status | stud_id |
+--------+------------+------------+---------+
| 1 | 2024-10-22 | PAID | 2 |
| 2 | 2024-10-22 | PAID | 1 |
| 3 | 2024-10-22 | NOT-PAID | 5 |
| 4 | 2024-10-22 | NOT-PAID | 3 |
| 5 | 2024-10-22 | NOT-PAID | 4 |
+--------+------------+------------+---------+
5 rows in set (0.00 sec)

mysql> insert into FURNITURE values(1,'CHAIR');


Query OK, 1 row affected (0.00 sec)

mysql> insert into FURNITURE values(2,'TABLE');


Query OK, 1 row affected (0.01 sec)

mysql> insert into FURNITURE values(3,'BED');


Query OK, 1 row affected (0.01 sec)

mysql> insert into FURNITURE values(4,'SOFA');


Query OK, 1 row affected (0.01 sec)

mysql> insert into FURNITURE values(5,' ');


Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM FRENITURE;;


ERROR 1146 (42S02): Table 'world.freniture' doesn't exist
ERROR:
No query specified

mysql> SELECT * FROM FURNITURE;


+--------+----------+
| fur_id | fur_type |
+--------+----------+
| 1 | CHAIR |
| 2 | TABLE |
| 3 | BED |
| 4 | SOFA |
| 5 | |
+--------+----------+
5 rows in set (0.00 sec)

mysql> insert into ROOM values(1,4,1,2);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ROOM values(2,4,2,1);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ROOM values(3,4,2,3);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ROOM values(4,4,2,4);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ROOM values(5,4,2,5);


Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM ROOM;


+---------+----------+----------+---------+
| room_id | capacity | furni_id | stud_id |
+---------+----------+----------+---------+
| 1 | 4 | 1 | 2 |
| 2 | 4 | 2 | 1 |
| 3 | 4 | 2 | 3 |
| 4 | 4 | 2 | 4 |
| 5 | 4 | 2 | 5 |
+---------+----------+----------+---------+
5 rows in set (0.00 sec)

mysql> INSERT INTO HOSTEL VALUES(1,'ANUJA_2','PUNE',20,80,2,1);


Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO HOSTEL VALUES(2,'ANUJA_1','PUNE',20,80,1,2);


Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO HOSTEL VALUES(3,'ANUJA_3','PUNE',20,80,3,4);


Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO HOSTEL VALUES(4,'ANUJA_4','PUNE',20,80,4,3);


Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO HOSTEL VALUES(5,'ANUJA_5','PUNE',20,80,5,5);


Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM HOSTEL;


+--------+----------+-------------+-----------+--------------+-------+-------+
| hos_id | hos_name | hos_address | hos_rooms | hos_students | ep_id | rm_id |
+--------+----------+-------------+-----------+--------------+-------+-------+
| 1 | ANUJA_2 | PUNE | 20 | 80 | 2 | 1 |
| 2 | ANUJA_1 | PUNE | 20 | 80 | 1 | 2 |
| 3 | ANUJA_3 | PUNE | 20 | 80 | 3 | 4 |
| 4 | ANUJA_4 | PUNE | 20 | 80 | 4 | 3 |
| 5 | ANUJA_5 | PUNE | 20 | 80 | 5 | 5 |
+--------+----------+-------------+-----------+--------------+-------+-------+
5 rows in set (0.00 sec)

You might also like