0% found this document useful (0 votes)
45 views6 pages

Practical 4

The document contains 15 SQL queries related to employee database tables. The queries perform operations like selecting, inserting, updating, deleting and altering table data.

Uploaded by

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

Practical 4

The document contains 15 SQL queries related to employee database tables. The queries perform operations like selecting, inserting, updating, deleting and altering table data.

Uploaded by

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

Practical : 4

1. List total deposit from deposit.

QUERY: SELECT SUM(AMOUNT) FROM DEPOSIT;

2. List total loan from karolbagh branch.

QUERY: SELECT SUM(AMOUNT) FROM BORROW WHERE


BNAME="KAROLBAGH";

3. Give maximum loan from branch vrce.

QUERY: SELECT MAX(AMOUNT) FROM BORROW WHERE


BNAME="VRCE";

4. Count total number of customers.

QUERY: SELECT COUNT(*) FROM CUSTOMERS;

5. Count total number of customer's cities.

QUERY: SELECT COUNT(DISTINCT CITY) FROM CUSTOMERS;

6. Create table supplier from employee with all the columns.

QUERY: CREATE TABLE SUPPLIER AS SELECT * FROM


EMPLOYEE;

7. Create table sup1 from employee with first two columns.

QUERY: CREATE TABLE SUP1 AS SELECT EMP_NO,EMP_NAME


FROM EMPLOYEE;

8. Create table sup2 from employee with no data.

Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15


QUERY: CREATE TABLE SUP2 LIKE EMPLOYEE;

9. Insert the data into sup2 from employee whose second


character should be 'n' and string should be 5 characters
long in employee name field.

QUERY: INSERT INTO SUP2 SELECT * FROM EMPLOYEE WHERE


EMP_NAME LIKE "_N___";

10.Delete all the rows from sup1.

QUERY: DELETE FROM SUP1;

11.Delete the detail of supplier whose sup_no is 103.

QUERY: DELETE FORM SUPPLIER WHERE EMP_NO = 103;

12.Rename the table sup2.

QUERY: ALTER TABLE SUP2 RENAME S2;

13.Destroy table sup1 with all the data.

QUERY: DROP TABLE SUP1;

14.Update the value dept_no to 10 where second character of


emp. name is 'm'.

QUERY: UPDATE EMPLOYEE SET DEPT_NO=10 WHERE


EMP_NAME LIKE “_M%”;

15.Update the value of employee name whose employee


number is 103.

QUERY: UPDATE EMPLOYEE EMP_NAME =”XYZ” WHERE


EMP_NO = 103;
Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15
Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15
Practical : 5

(1) Write a query to display the current date. Label the column Date
QUERY:
SELECT CURRENT_DATE() AS DATE;

(2) For each employee, display the employee number, job, salary, and
salary increased by 15% and expressed as a whole number. Label the
column New Salary
QUERY:
UPDATE EMPLOYEE SET NEW_SALARY = 1.15*EMP_SAL;

(3) Modify your query no (2) to add a column that subtracts the old
salary from the new salary. Label the column Increase
QUERY:
ALTER TABLE EMPLOYEE ADD NEW_SALARY INT(8), INCREASE INT(8)
UPDATE EMPLOYEE SET NEW_SALARY = 1.15*EMP_SAL,
INCREASE=NEW_SALARY-EMP_SAL;

(4) Write a query that displays the employee’s names with the first
letter capitalized and all other letters lowercase, and the length of the
names, for all employees whose name starts with J, A, or M. Give each
column an appropriate label. Sort the results by the employees’
names.
QUERY:
SELECT
CONCAT(UPPER(SUBSTR(EMP_NAME,1,1)),LOWER(SUBSTR(EMP_NAME,
2))) AS QNAME, LENGTH(EMP_NAME) AS QLEN FROM EMPLOYEE
WHERE EMP_NAME LIKE 'J%' OR EMP_NAME LIKE 'A%' OR EMP_NAME
LIKE 'M%';

(5) Write a query that produces the following for each employee:
<employee name> earns <salary> monthly
QUERY:
SELECT CONCAT(EMP_NAME," EARNS ",EMP_SAL," MONTHLY") AS
STATEMENT FROM EMPLOYEE;

Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15


(6) Display the name, hire date, number of months employed and day
of the week on which the employee has started Order the results by
the day of the week starting with Monday
QUERY:
SELECT
EMP_NAME,HIRE_DATE,TIMESTAMPDIFF(MONTH,HIRE_DATE,SYSDATE()
) AS "MONTHS-EMPLOYED",DAYNAME(HIRE_DATE) AS DAY FROM
EMPLOYEE ORDER BY DAY;

(7) Display the hiredate of emp in a format that appears as Seventh of


June 1994 12:00:00 AM.
QUERY:
SELECT CONCAT(DATE_FORMAT(HIRE_DATE,"%D OF %M, %Y
"),CURRENT_TIME()) FROM EMPLOYEE;

(8) Write a query to calculate the annual compensation of all


employees (sal+comm.)
QUERY:
SELECT (EMP_SAL+COMP) FROM EMPLOYEE;

Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15


Enrollment No: 220280107126 BE 3rd Sem CE,CE Dept,LDCE-A’bad-15

You might also like