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

Class 12

Uploaded by

msakthivel.chn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Class 12

Uploaded by

msakthivel.chn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

INFORMATION TECHOLOGY (802)

Sno Practical on Signature


of the
teacher
SQL
1. Relation - Student (Create,Insert,View,Delete)

2. Relation – Employee (Create,Insert,Select,Alter,Update)

3. Relation - (Select)

4. Relation – (Aggregated Functions)

5. Relation (Join Relation)


Practical : 02

Date :

RELATION –EMPLOYEE
(Create, Insert,Select,Alter,Update)
Consider the following Employee table:

Ta ble ame: Employee

T
h
e primary key of this table is Employee_ID and Manager_ID is a foreign key that references

Employee_ID.

Write SQL commands for the following:

1. Create the above table.


2. Insert values as shown above.
3. Update the salary of “Amyra” to 40000.
4. Alter the table Employee by adding a new column phnone_num.
5. Write a query to display names and salaries of those employees whose salary are
greater than 20000.
6. Write a query to display name,salary and bonus details of employees in descending
order of salary.
7. Write a query to display the names of employees whose name contains “a” as the last
alphabet.
8. Write a query to display the name and Job title of those employees whose Manager_ID
is 1201.
9. Write a query to display the name and Job title of those employees whose Manager is
“Amyra”.
10. Write a query to display the name and Job title of those employees aged between 26
years and 30 years (both inclusive)

QUERIES
1. Create the above table.

mysql> CREATE TABLE EMPLOYEE(EMPLOYEE_ID INTEGER PRIMARY


KEY,EMPLOYEE_NAME CHAR(20),JOB_TITLE CHAR(20),SALARY INTEGER,BONUS
INTEGER,AGE INTEGER,MANAGER_ID INTEGER);

Query OK, 0 rows affected (0.06 sec)

2. Insert values as shown above.

mysql>INSERT INTO EMPLOYEE VALUES (1201,”DIVYA”,”PRESIDENT”,50000,NULL ,29,NULL);


Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO EMPLOYEE VALUES (1205,”AMYRA”,”MANAGER”,30000,2500 ,26,1201);


Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO EMPLOYEE VALUES (1211,”RAHUL”,”ANALYST”,20000,1500 ,23,1205);


Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO EMPLOYEE VALUES (1213,”MANISH”,”SALESMAN”,15000,NULL


,22,1205);
Query OK, 1 row affected (0.03 sec)
mysql> INSERT INTO EMPLOYEE VALUES (1216,”MEGHA”,”ANALYST”,22000,1300 ,25,1201);
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO EMPLOYEE VALUES (1217,”MOHIT”,”SALESMAN”,16000,NULL


,22,1205);
Query OK, 1 row affected (0.01 sec)

3. Update the salary of “Amyra” to 40000.


mysql> UPDATE EMPLOYEE SET SALARY = 40000 WHERE EMPLOYEE_NAME="AMYRA";
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0

4. Alter the table Employee by adding a new column phnone_num.


mysql> ALTER TABLE EMPLOYEE ADD (PHONE_NUM INTEGER);
Query OK, 6 rows affected (0.08 sec)
Records: 6 Duplicates: 0 Warnings: 0
5. Write a query to display names and salaries of those employees whose
salary are greater than 20000.

mysql> SELECT EMPLOYEE_NAME,SALARY FROM EMPLOYEE WHERE


SALARY>20000;
+---------------+----------------+
| EMPLOYEE_NAME | SALARY |
+---------------+-----------------+
| Divya | 50000 |
| Amyra | 40000 |
| Megha | 22000 |
+---------------+-----------------+
3 rows in set (0.00 sec)

6. Write a query to display name,salary and bonus details of employees in


descending order of salary.
MYSQL> SELECT EMPLOYEE_NAME,SALARY,BONUS FROM EMPLOYEE ORDER BY
SALARY DESC;
+--------------------+--------+-------+
| employee_name | salary | bonus |
+--------------------+--------+-------+
| Divya | 50000 | NULL |
| Amyra | 40000 | 2500 |
| Megha | 22000 | 1300 |
| Rahul | 20000 | 1500 |
| Mohit | 16000 | NULL |
| Manish | 15000 | NULL |
+---------------------+--------+-------+
6 rows in set (0.00 sec)

7. Write a query to display the names of employees whose name contains


“a” as the last alphabet.
mysql> SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME
LIKE("%A");
+----------------------+
| EMPLOYEE_NAME |
+----------------------+
| Divya |
| Amyra |
| Megha |
+----------------------+
3 rows in set (0.00 sec)
8. Write a query to display the name and Job title of those employees
whose Manager_ID is 1201.
mysql>SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE WHERE
MANAGER_ID =1201;
+--------------------+-----------------+
| EMPLOYEE_NAME | JOB_TITLE |
+----------------------+----------------+
| Amyra | Manager |
| Megha | Analyst |
+-----------------------+---------------+
2 rows in set (0.00 sec)

9. Write a query to display the name and Job title of those employees
whose Manager is “Amyra”.
mysql> SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE WHERE
EMPLOYEE_NAME="Amyra" AND JOB_TITLE="MANAGER";
+---------------------+----------------+
| EMPLOYEE_NAME | JOB_TITLE |
+---------------------+---------------+
| Amyra | Manager |
+--------------------+-----------------+
1 row in set (0.00 sec)

10. Write a query to display the name and Job title of those employees
aged between 26 years and 30 years (both inclusive)

mysql> SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE WHERE AGE


BETWEEN 26 AND 30;
+--------------------------+---------------------+
| EMPLOYEE_NAME | JOB_TITLE |
+---------------------------+----------------------+
| Divya | President |
| Amyra | Manager |
+---------------------------+---------------------+
2 rows in set (0.01 sec)

You might also like