Assignment of Queries: NAME: Kamran Amin Roll No.: 109-BSCS-2017 Section: A Submitted To: Maam Asma Kanwal
Assignment of Queries: NAME: Kamran Amin Roll No.: 109-BSCS-2017 Section: A Submitted To: Maam Asma Kanwal
(a)
Consider the following “worker” table and write the SQL queries according to the criteria given
below:
1. Write an SQL Query To Fetch The Count Of Employees Working In The Department
‘Admin’.
Sol.
SELECT COUNT(WORKER_ID) FROM WORKER
WHERE DEPARTMENT=’ADMIN’;
2. Write An SQL Query To Insert a new record in the worker’s table.
Sol.
INSERT INTO WORKER (WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING,
DEPARTMENT)
VALUES (009, ‘BILAL’, ‘AHMAD’, 80000, 2019-5-4, 9:00:00,’COMPUTER-SCIENCE’);
3. Write An SQL Query To Update Salary to 60000 if Worker_ID is 005.
Sol.
UPDATE WORKER SET SALARY=60000 WHERE WORKER_ID=005;
4. Write An SQL Query To delete record of Vipul.
Sol.
DELETE FROM WORKER WHERE FIRST_NAME=’VIPUL’;
5. Write An SQL Query To Print Details Of The Workers Whose FIRST_NAME Ends With
‘A’.
Sol.
SELECT * FROM WORKER
WHERE FIRST_NAME IN ‘%A’;
6. Write An SQL Query To Print All Worker Details From The Worker Table Order By
FIRST_NAME Ascending.
Sol.
SELECT * FROM WORKER ORDER BY FIRST_NAME ASC;
(b)Define a queries for the Books database. Provide the following predefined queries in C#.
a) Select all authors from the Authors table.
Sol.
SELECT * FROM AUTHORS
c) Select a specific author and list all books for that author. Include the title, year and ISBN
number.
Sol.
SELECT * FROM AUTHORS
INNER JOIN BOOKDETAILS
ON AUTHORS.AUTHORS_ID IN (SELECT AUTHORS_ID FROM BOOKDETAILS WHERE
AUTHORS_ID=009);
d) Select a specific publisher and list all books published by that publisher. Include the title,
year and ISBN number.
Sol.
SELECT * FROM PUBLISHERS
INNER JOIN BOOKDETAILS
ON PUBLISHERS.PUBLISHERS_ID IN (SELECT PUBLISHERS_ID FROM BOOKDETAILS
WHERE PUBLISHERS_ID=005);
e) Provide a query that insert new record of author and publishers in tables.
Sol.
INSERT INTO AUTHORS (AUTHORS_ID, AUTHORS_NAME)
VALUES (009,’GHALIB’);