Document Sid
Document Sid
Lab 1, 2 & 3
Theory
The CREATE DATABASE statement is used to create a new SQL database.
The CREATE TABLE statement is used to create a new table in a database.
The DESC command is used to sort the data returned in descending order.
The INSERT INTO statement is used to insert new records in a table.
The SELECT statement is used to select data from a database.
The UPDATE statement is used to modify the existing records in a table.
The SELECT DISTINCT statement is used to return only distinct (different) values.
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
MySQL's aggregate function is used to perform calculations on multiple values and return the result in
a single value like the average of all values count(): It returns the number of rows, including
rows with NULL values in a group. sum(): It returns the total summed values (Non-NULL) in a
set.
average(): It returns the average value of an expression.
min(): It returns the minimum (lowest) value in a set.
max(): It returns the maximum (highest) value in a set.
The DELETE statement is used to delete existing records in a table.
The PRIMARY KEY constraint uniquely identifies each record in a table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key; and in the table, this primary key can consist of single
or multiple columns (fields).
+----------------------------------------------------------------------------+
CODE:
Page1 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into student values(34, "Garvit", "M", 18, "CSE");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(140, "Ram Sharma", "M", 18, "CSE");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(150, "Devansh Singh", "M", 19, "ME");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(155, "Shruti Malviya", "F", 19, "CE");
Query OK, 1 row affected (0.01 sec)
mysql> insert into student values(159, "Dipika Jain", "F", 19, "IT");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(170, "Sakshi Sharma", "F", 18, "AU");
Query OK, 1 row affected (0.00 sec)
Page2 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
11 rows in set (0.01 sec)
mysql> insert into faculty values(101, "Rohit Mahajan", "M", 30, "ME",
344.9,'2008');
Query OK, 1 row affected (0.01 sec)
mysql> insert into faculty values(106, "Monika Jain", "F", 25, "CSE",
548.0,'2009');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(102, "Kiran Talwariya", "F", 34, "IT",
783.0,'2012');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(110, "Jitendra Sharma", "M", 45, "CE",
993.0,'2005');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(107, "Sheetal Agrawal", "F", 40, "AU",
678.0,'2009');
Query OK, 1 row affected (0.01 sec)
mysql> insert into faculty values(105, "Rahul Sharma", "M", 51, "ME",
693.0,'2010');
Query OK, 1 row affected (0.00 sec)
mysql> select * from faculty;
+------------+-----------------+--------+------+------+--------+-------------+
| Faculty_id | Name | Gender | Age | Dept | Salary | Year_joined |
+------------+-----------------+--------+------+------+--------+-------------+
| 101 | Rohit Mahajan | M | 30 | ME | 344.90 | 2008 |
Page3 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 106 | Monika Jain | F | 25 | CSE | 548.00 | 2009 |
| 102 | Kiran Talwariya | F | 34 | IT | 783.00 | 2012 |
| 110 | Jitendra Sharma | M | 45 | CE | 993.00 | 2005 |
| 107 | Sheetal Agrawal | F | 40 | AU | 678.00 | 2009 |
| 105 | Rahul Sharma | M | 51 | ME | 693.00 | 2010 |
+------------+-----------------+--------+------+------+--------+-------------+
6 rows in set (0.00 sec)
mysql> update student set gender = 'F' where name = 'Anshika Gupta';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> update student set age=19 where enrollment_num in (34, 140, 59, 170);
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> update student set age=18 where enrollment_num not in (34, 140, 59, 170);
Query OK, 6 rows affected (0.00 sec)
Rows matched: 7 Changed: 6 Warnings: 0
mysql> update student set name = "Diksha Rathore" where name = "Diksha";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Neha Reddy" where name = "Neha";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> update student set name = "Gaurav Sharma" where name = "Gaurav";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Garvit Paliwal" where name = "Garvit";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Kratik Mathur" where name = "Kratik";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Aayushi Talreja" where name = "Aayushi";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Mohit Pherwani" where name = "Mohit";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update faculty set Name = "Karan Singh" where Faculty_id = 102;
Page4 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
Page5 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> select name from student where branch='CSE';
+----------------+
| name |
+----------------+
| Garvit Paliwal |
| Ram Sharma |
+----------------+ 2
rows in set (0.00 sec)
mysql> select * from faculty where Year_joined between 2000 and 2009;
+------------+-----------------+--------+------+------+--------+-------------+ |
Faculty_id | Name | Gender | Age | Dept | Salary | Year_joined |
+------------+-----------------+--------+------+------+--------+-------------+
| 101 | Rohit Mahajan | M | 30 | ME | 344.90 | 2008 |
| 106 | Monika Jain | F | 25 | CSE | 548.00 | 2009 |
| 110 | Jitendra Sharma | M | 45 | CE | 993.00 | 2005 |
| 107 | Sheetal Agrawal | F | 40 | AU | 678.00 | 2009 |
+------------+-----------------+--------+------+------+--------+-------------+
4 rows in set (0.00 sec)
Page6 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
+------------+-----------------+--------+------+------+--------+-------------+
| Faculty_id | Name | Gender | Age | Dept | Salary | Year_joined |
+------------+-----------------+--------+------+------+--------+-------------+
| 101 | Rohit Mahajan | M | 30 | ME | 344.90 | 2008 |
| 102 | Karan Singh | F | 34 | IT | 783.00 | 2012 |
| 105 | Rahul Sharma | M | 51 | ME | 693.00 | 2010 |
| 106 | Monika Jain | F | 25 | CSE | 548.00 | 2009 |
| 107 | Sheetal Agrawal | F | 40 | AU | 678.00 | 2009 |
| 110 | Jitendra Sharma | M | 45 | CE | 993.00 | 2005 |
+------------+-----------------+--------+------+------+--------+-------------+
6 rows in set (0.00 sec)
Page7 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 18.3636 |
+----------+ 1 row in
set (0.00 sec)
mysql> create table cs_dept(id int primary key, fname char(20) unique key, lname
char(20), age smallint, dob date not null); Query OK, 0 rows affected (0.01 sec)
Page8 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into cs_dept values(203, "Maddison", "Atkins", 22,"2000-09-16");
Query OK, 1 row affected (0.00 sec)
Page9 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
Lab 4
Theory
The REGEXP_LIKE() function in MySQL is used for pattern matching. It compares whether the given
strings match a regular expression or not. It returns 1 if the strings match the regular expression and
return 0 if no match is found.
+----------------------------------------------------------------------------+
CODE:
Page10 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> drop table cs_dept; Query OK,
0 rows affected (0.01 sec)
Page11 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| studentID | Full_Name |
+-----------+-----------------+
| 44 | Aayushi Talreja |
| 150 | Devansh Singh |
| 159 | Dipika Jain |
| 34 | Garvit Paliwal |
| 39 | Gaurav Sharma |
| 47 | Kratik Mathur |
| 67 | Mohit Pherwani |
| 140 | Ram Sharma |
| 170 | Sakshi Sharma |
| 155 | Shruti Malviya |
+-----------+-----------------+
10 rows in set (0.00 sec)
Page12 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> select * from faculty limit 3;
+------------+---------------+--------+------+------+------+-------------+
| Faculty_id | Name | Gender | Age | DOB | Dept | Year_joined |
+------------+---------------+--------+------+------+------+-------------+
| 101 | Rohit Mahajan | M | 30 | NULL | ME | 2008 |
| 102 | Karan Singh | F | 34 | NULL | IT | 2012 |
| 105 | Rahul Sharma | M | 51 | NULL | ME | 2010 |
+------------+---------------+--------+------+------+------+-------------+
3 rows in set (0.00 sec)
mysql>
Lab 5
Theory
The INNER JOIN keyword selects records that have matching values in both tables.
The LEFT JOIN keyword returns all records from the left table (table1), and the matching records (if
any) from the right table (table2).
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records (if
any) from the left table (table1).
The CROSS JOIN keyword returns all records from both tables (table1 and table2).
Page13 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
+----------------------------------------------------------------------------+
CODE:
Page14 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into customers values(102, "Udit", "Sathe");
Query OK, 1 row affected (0.00 sec)
Page15 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| customerID | fname | lname | customerCODE | orderID |
+------------+---------+-----------+--------------+---------+
| 100 | Monika | Jain | 100 | 1001 |
| 101 | Salmon | Khan | 101 | 1002 |
| 102 | Udit | Sathe | 102 | 1003 |
| 103 | Utkarsh | Chourasia | 103 | 1004 |
| 104 | Muskan | Jain | 104 | 1005 |
+------------+---------+-----------+--------------+---------+
5 rows in set (0.00 sec)
Page16 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 100 | Monika | Jain | 104 | 1005 |
| 100 | Monika | Jain | 103 | 1004 |
| 100 | Monika | Jain | 102 | 1003 |
| 100 | Monika | Jain | 101 | 1002 |
| 100 | Monika | Jain | 100 | 1001 |
| 101 | Salmon | Khan | 104 | 1005 |
| 101 | Salmon | Khan | 103 | 1004 |
| 101 | Salmon | Khan | 102 | 1003 |
| 101 | Salmon | Khan | 101 | 1002 |
| 101 | Salmon | Khan | 100 | 1001 |
| 102 | Udit | Sathe | 104 | 1005 |
| 102 | Udit | Sathe | 103 | 1004 |
| 102 | Udit | Sathe | 102 | 1003 |
| 102 | Udit | Sathe | 101 | 1002 |
| 102 | Udit | Sathe | 100 | 1001 |
| 103 | Utkarsh | Chourasia | 104 | 1005 |
| 103 | Utkarsh | Chourasia | 103 | 1004 |
| 103 | Utkarsh | Chourasia | 102 | 1003 |
| 103 | Utkarsh | Chourasia | 101 | 1002 |
| 103 | Utkarsh | Chourasia | 100 | 1001 |
| 104 | Muskan | Jain | 104 | 1005 |
| 104 | Muskan | Jain | 103 | 1004 |
| 104 | Muskan | Jain | 102 | 1003 |
| 104 | Muskan | Jain | 101 | 1002 |
| 104 | Muskan | Jain | 100 | 1001 |
| 105 | Tejas | Shah | 104 | 1005 |
| 105 | Tejas | Shah | 103 | 1004 |
| 105 | Tejas | Shah | 102 | 1003 |
| 105 | Tejas | Shah | 101 | 1002 |
| 105 | Tejas | Shah | 100 | 1001 |
| 106 | Sneha | Verma | 104 | 1005 |
| 106 | Sneha | Verma | 103 | 1004 |
| 106 | Sneha | Verma | 102 | 1003 |
| 106 | Sneha | Verma | 101 | 1002 |
| 106 | Sneha | Verma | 100 | 1001 |
| 107 | Vanhika | Juneja | 104 | 1005 |
| 107 | Vanhika | Juneja | 103 | 1004 |
| 107 | Vanhika | Juneja | 102 | 1003 |
| 107 | Vanhika | Juneja | 101 | 1002 |
| 107 | Vanhika | Juneja | 100 | 1001 |
| 108 | Sparsh | Garg | 104 | 1005 |
| 108 | Sparsh | Garg | 103 | 1004 |
| 108 | Sparsh | Garg | 102 | 1003 |
| 108 | Sparsh | Garg | 101 | 1002 |
| 108 | Sparsh | Garg | 100 | 1001 |
Page17 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 109 | Ujjwal | Pawar | 104 | 1005 |
| 109 | Ujjwal | Pawar | 103 | 1004 |
| 109 | Ujjwal | Pawar | 102 | 1003 |
| 109 | Ujjwal | Pawar | 101 | 1002 |
| 109 | Ujjwal | Pawar | 100 | 1001 |
| 110 | Tanish | Kohser | 104 | 1005 |
| 110 | Tanish | Kohser | 103 | 1004 |
| 110 | Tanish | Kohser | 102 | 1003 |
| 110 | Tanish | Kohser | 101 | 1002 |
| 110 | Tanish | Kohser | 100 | 1001 |
+------------+---------+-----------+--------------+---------+
55 rows in set (0.00 sec)
mysql>
Lab 6
Theory
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or
more real tables in the database.
You can add SQL statements and functions to a view and present the data as if the data were coming
from one single table.
A view is created with the CREATE VIEW statement.
+----------------------------------------------------------------------------+
CODE:
Page18 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into student values(34, "Garvit", "M", 18, "CSE");
Query OK, 1 row affected (0.03 sec)
mysql> insert into student values(140, "Ram Sharma", "M", 18, "CSE");
Query OK, 1 row affected (0.04 sec)
mysql> insert into student values(150, "Devansh Singh", "M", 19, "ME");
Query OK, 1 row affected (0.04 sec)
mysql> insert into student values(155, "Shruti Malviya", "F", 19, "CE");
Query OK, 1 row affected (0.04 sec)
mysql> insert into student values(159, "Dipika Jain", "F", 19, "IT");
Query OK, 1 row affected (0.01 sec)
mysql> insert into student values(170, "Sakshi Sharma", "F", 18, "AU");
Query OK, 1 row affected (0.01 sec)
mysql> update student set gender = 'F' where name = 'Anshika Gupta';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> update student set age=19 where enrollment_num in (34, 140, 59, 170);
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> update student set age=18 where enrollment_num not in (34, 140, 59, 170);
Query OK, 6 rows affected (0.01 sec)
Rows matched: 7 Changed: 6 Warnings: 0
mysql> update student set name = "Diksha Rathore" where name = "Diksha";
Query OK, 1 row affected (0.01 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Neha Reddy" where name = "Neha";
Page19 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> update student set name = "Gaurav Sharma" where name = "Gaurav";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Garvit Paliwal" where name = "Garvit";
Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1
Warnings: 0 mysql> update student set name = "Kratik Mathur" where name
Changed: 1 Warnings: 0
mysql> update student set name = "Aayushi Talreja" where name = "Aayushi";
Query OK, 1 row affected (0.00 sec) Rows
matched: 1 Changed: 1 Warnings: 0
mysql> update student set name = "Mohit Pherwani" where name = "Mohit";
Query OK, 1 row affected (0.01 sec) Rows
matched: 1 Changed: 1 Warnings: 0
Page20 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate
functions.
The UNION operator is used to combine the result-set of two or more SELECT statements.
Every SELECT statement within UNION must have the same number of columns
The columns must also have similar data types
The columns in every SELECT statement must also be in the same order
+----------------------------------------------------------------------------+
CODE:
Query OK, 1 row affected (0.00 sec) mysql> insert into student
(0.00 sec)
Page21 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into student values(39, "Gaurav", "M", 18, "CSBS");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(155, "Shruti Malviya", "F", 19, "CE");
Query OK, 1 row affected (0.01 sec)
mysql> insert into student values(159, "Dipika Jain", "F", 19, "IT");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(170, "Sakshi Sharma", "F", 18, "AU");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(140, "Ram Sharma", "M", 18, "CSE");
Query OK, 1 row affected (0.00 sec)
mysql> insert into student values(150, "Devansh Singh", "M", 19, "ME");
Query OK, 1 row affected (0.01 sec)
Page22 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 1 | Gaurav |
| 1 | Mohit |
| 1 | Shruti Malviya |
| 1 | Dipika Jain |
| 1 | Sakshi Sharma |
| 1 | Devansh Singh |
+-----------------------+----------------+
11 rows in set (0.00 sec)
Page23 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| 170 | Sakshi | F | 18 | AU |
+----------------+-----------+--------+------+--------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM student where gender="F" Having age=18 Union SELECT * FROM
student where gender="M" Having age=18; +----------------+-----------+--------
+------+--------+
| enrollment_num | full_name | gender | age | branch |
+----------------+-----------+--------+------+--------+
| 59 | Diksha | F | 18 | AU |
| 170 | Sakshi | F | 18 | AU |
| 34 | Garvit | M | 18 | CSE |
| 39 | Gaurav | M | 18 | CSBS |
| 140 | Ram | M | 18 | CSE |
+----------------+-----------+--------+------+--------+
5 rows in set (0.00 sec)
Page24 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
Lab 8
Theory
The EXISTS operator is used to test for the existence of any record in a subquery.
The EXISTS operator returns TRUE if the subquery returns one or more records.
The ANY operator:
returns a boolean value as a result
returns TRUE if ANY of the subquery values meet the condition
The ALL operator:
returns a boolean value as a result returns TRUE if ALL
of the subquery values meet the condition is used with SELECT,
WHERE and HAVING statements
+----------------------------------------------------------------------------+
CODE:
Page25 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into student values(39, "Gaurav", "M", 18, "CSBS");
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(106, "Monika Jain", "F", 25, "CSE",
Page26 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
548.0,'2009');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(102, "Kiran Talwariya", "F", 34, "IT",
783.0,'2012');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(110, "Jitendra Sharma", "M", 45, "CE",
993.0,'2005');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(107, "Sheetal Agrawal", "F", 40, "AU",
678.0,'2009');
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(105, "Rahul Sharma", "M", 51, "ME",
693.0,'2010');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT full_name FROM student WHERE EXISTS (SELECT branch FROM
faculty WHERE age=25 );
+-----------+
| full_name |
+-----------+
| Garvit |
| Aayushi |
| Kratik |
| Diksha |
| Gaurav |
| Mohit |
| Ram |
| Devansh |
| Shruti |
| Shruti |
| Dipika |
| Saksh |
+-----------+
12 rows in set (0.00 sec)
mysql> SELECT full_name FROM student WHERE branch=ANY (SELECT branch FROM
faculty WHERE age>38 );
+-----------+
| full_name |
+-----------+
| Kratik |
| Diksha |
Page27 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
| Devansh |
| Shruti |
| Saksh |
+-----------+
5 rows in set (0.00 sec)
mysql> SELECT full_name FROM student WHERE branch=ALL (SELECT branch FROM
faculty WHERE Gender="F" );
Empty set (0.00 sec)
Page28 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
Lab 9
Theory
The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY
in another table.
ON DELETE CASCADE clause in MySQL is used to automatically remove the matching records from the
child table when we delete the rows from the parent table. It is a kind of referential action related to
the foreign key.
A foreign key with "set null on delete" means that if a record in the parent table is deleted, then the
corresponding records in the child table will have the foreign key fields set to NULL. The records in the
child table will not be deleted in SQL Server.
+----------------------------------------------------------------------------+
CODE:
Page29 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
mysql> insert into student values(105, "Devansh", "M", 19, "ME");
Query OK, 1 row affected (0.01 sec)
mysql> create table faculty(Faculty_id int primary key, Name char(30), Gender
char(1), Age int, branch char(10), Salary float(5, 2), Year_joined year,student_en
int, FOREIGN KEY (student_en) REFERENCES student(enrollment_num) ON DELETE SET
NULL);
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> insert into faculty values(101, "Rohit Mahajan", "M", 30, "ME",
344.9,'2008', 101);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(106, "Monika Jain", "F", 25, "CSE",
548.0,'2009', 106);
Query OK, 1 row affected (0.01 sec)
mysql> insert into faculty values(110, "Jitendra Sharma", "M", 45, "EC",
993.0,'2005', 102);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(107, "Sheetal Agrawal", "F", 40, "AU",
678.0,'2009', 105);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(105, "Rahul Sharma", "M", 51, "ME",
693.0,'2010', 105);
Query OK, 1 row affected (0.01 sec)
Page30 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
+-------------+------------+------+-----+---------+-------+
| Faculty_id | int | NO | PRI | NULL | |
| Name | char(30) | YES | | NULL | |
| Gender | char(1) | YES | | NULL | |
| Age | int | YES | | NULL | |
| branch | char(10) | YES | | NULL | |
| Salary | float(5,2) | YES | | NULL | |
| Year_joined | year | YES | | NULL | |
| student_en | int | YES | MUL | NULL | |
+-------------+------------+------+-----+---------+-------+
8 rows in set (0.01 sec)
mysql> insert into faculty values(101, "Rohit Mahajan", "M", 30, "ME",
344.9,'2008', 101);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(106, "Monika Jain", "F", 25, "CSE",
548.0,'2009', 106);
Query OK, 1 row affected (0.01 sec)
mysql> insert into faculty values(110, "Jitendra Sharma", "M", 45, "EC",
993.0,'2005', 102);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(107, "Sheetal Agrawal", "F", 40, "AU",
678.0,'2009', 105);
Query OK, 1 row affected (0.00 sec)
mysql> insert into faculty values(105, "Rahul Sharma", "M", 51, "ME",
693.0,'2010', 105);
Query OK, 1 row affected (0.01 sec)
Page31 CS3CO25
EN20CS301479 Utkarsh Chourasia CS-H Database Management Systems
+------------+-----------------+--------+------+--------+--------+-------------
+-----------+
| Faculty_id | Name | Gender | Age | branch | Salary | Year_joined |
student_en |
+------------+-----------------+--------+------+--------+--------+-------------
+-----------+
| 101 | Rohit Mahajan | M | 30 | ME | 344.90 | 2008 |
101 |
| 105 | Rahul Sharma | M | 51 | ME | 693.00 | 2010 |
105 |
| 106 | Monika Jain | F | 25 | CSE | 548.00 | 2009 |
106 |
| 107 | Sheetal Agrawal | F | 40 | AU | 678.00 | 2009 |
105 |
| 110 | Jitendra Sharma | M | 45 | EC | 993.00 | 2005 |
102 |
+------------+-----------------+--------+------+--------+--------+-------------
+-----------+
5 rows in set (0.00 sec)
Page32 CS3CO25