0% found this document useful (0 votes)
28 views3 pages

Assignment 2

The document shows SQL commands used to create an Employee table in the school database, insert data into the table, perform various queries on the table like sorting, filtering, updating and deleting records. Records for 5 employees with details like id, name, department, contact and manager id were inserted into the table. Various queries were run to select, update, delete records based on different criteria.

Uploaded by

SHIKHA BANSAL
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)
28 views3 pages

Assignment 2

The document shows SQL commands used to create an Employee table in the school database, insert data into the table, perform various queries on the table like sorting, filtering, updating and deleting records. Records for 5 employees with details like id, name, department, contact and manager id were inserted into the table. Various queries were run to select, update, delete records based on different criteria.

Uploaded by

SHIKHA BANSAL
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/ 3

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| advik |
| employee |
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
7 rows in set (0.02 sec)

mysql> use school;


Database changed
mysql> create table Employee(Empid int,EmpName varchar(100),Department
varchar(100),ContactNo int,EmailId varchar(100),EmpHeadId int);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into
Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(101,'ISHA','E-
101',1234567890,'isha@gmail.com',105);
Query OK, 1 row affected (0.02 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(102,'PRIYA','E
-104',1234567890,'priya@yahoo.com',101);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(103,'NEHA','E-
101',1234567890,'neha@gmail.com',101);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(104,'RAHUL','E
-102',1234567890,'rahul@yahoo.com',105);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(105,'ABHISHEK'
,'E-101',1234567890,'abhishek@gmail.com',102);
Query OK, 1 row affected (0.01 sec)

mysql> select * from Employee;


+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+
5 rows in set (0.00 sec)

mysql> select EmpName from Employee order by EmpName DESC;


+----------+
| EmpName |
+----------+
| RAHUL |
| PRIYA |
| NEHA |
| ISHA |
| ABHISHEK |
+----------+
5 rows in set (0.01 sec)

mysql> select * from Employee where EmpName like('P%');


+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
+-------+---------+------------+------------+-----------------+-----------+
1 row in set (0.00 sec)

mysql> select * from Employee where Department='E-104' or Department='E-102';


+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
+-------+---------+------------+------------+-----------------+-----------+
2 rows in set (0.00 sec)

mysql> select EmpName from Employee where EmpName like ('%A');


+---------+
| EmpName |
+---------+
| ISHA |
| PRIYA |
| NEHA |
+---------+
3 rows in set (0.00 sec)
mysql> select * from Employee where EmpId=104 and EmpHeadId=105;
+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
+-------+---------+------------+------------+-----------------+-----------+
1 row in set (0.00 sec)
mysql> select * from Employee where EmailId like ('__H%');
+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+

mysql>
mysql> select * from Employee where EmailId like ('%gmail.com');
+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+
3 rows in set (0.00 sec)

mysql> delete from employee where Department =('E-104');


Query OK, 1 row affected (0.00 sec)

mysql> select * from employee;


+-------+----------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+-----------------+-----------+
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | ts123@gmail.com | 102 |
+-------+----------+------------+------------+-----------------+-----------+
3 rows in set (0.00 sec)
mysql> update employee set Department=('E-111') where EmpHeadId=('105');
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee;


+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+

mysql> update Employee set EmailId=('ts123@gmail.com') where EmpName=('ABHISHEK');


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee;


+-------+----------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | ts123@gmail.com | 102 |
+-------+----------+------------+------------+-----------------+-----------+
4 rows in set (0.00 sec)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy