You are on page 1of 5

PRACTICAL 4

AIM: To create given table and perform different tasks on the table.

The above table was created using queries:-

Queries:
To create a new table FACULTY.

mysql>USE FACULTY;

Database changed

mysql>CREATE TABLE FACULTY (EMP_ID INT,EMP_NAME VARCHAR(20),DEPT_NAME


VARCHAR(20),DEPT_CODE VARCHAR(20));

Query OK,0 rows affected(0.26 sec)

To insert values into the table FACULTY.

mysql> INSERT INTO FACULTY VALUES

(102,"HARRY","PHARMA","PHA"),(103,"MOHAN","COMPUTER","CSE"),(104,"RAMU","CIVIL","CE"),
(105,"SHYAM","COMPUTER","CSE"),(106,"GEETA","MECHANICAL","ME"),(107,"ARYAN","CHEMICAL","CH");

Query OK, 6 rows affected (0.11 sec)

Presented By: Shivam Roll Number:170102185


Task 1: Display distinct department names from the table.
Syntax: SELECT DISTINCT DEPT_NAME FROM FACULTY;

Query:

Task 2: Update Department code of PHARMA from PHA to PHAR.


Syntax: UPDATE FACULTY SET DEPT_CODE=’’PHAR” WHERE EMP_ID=102;

Query:

Presented By: Shivam Roll Number:170102185


Task 3: Delete 5th row from the table.
Syntax: DELETE FROM FACULTY WHERE EMP_ID=105;

Query:

Task 4: Display names of all employees starting with ‘R’.


Syntax: SELECT EMP_NAME FROM FACULTY WHERE EMP_NAME LIKE ‘R%’;

Query:

Presented By: Shivam Roll Number:170102185


Task 5: Display names of all the employees ending with ‘N’.
Syntax: SELECT EMP_NAME FROM FACULTY WHERE EMP_NAME LIKE ‘%N’;

Query:

Task 6: Delete DEPT_CODE completely from the table.


Syntax: ALTER TABLE FACULTY DROP DEPT_CODE;

Query:

Presented By: Shivam Roll Number:170102185


Presented By: Shivam Roll Number:170102185

You might also like