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

Assignment of Queries: NAME: Kamran Amin Roll No.: 109-BSCS-2017 Section: A Submitted To: Maam Asma Kanwal

This document contains two assignments involving writing SQL queries. The first assignment (a) provides a worker table and asks to write queries for various criteria like counting employees in a department, inserting a new record, updating a salary, deleting a record, and selecting records by name. The second assignment (b) asks to define queries for a Books database, including selecting all authors and publishers, selecting books by a specific author or publisher, and inserting new author, publisher, and book records.

Uploaded by

Faisal Shehzad
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 views3 pages

Assignment of Queries: NAME: Kamran Amin Roll No.: 109-BSCS-2017 Section: A Submitted To: Maam Asma Kanwal

This document contains two assignments involving writing SQL queries. The first assignment (a) provides a worker table and asks to write queries for various criteria like counting employees in a department, inserting a new record, updating a salary, deleting a record, and selecting records by name. The second assignment (b) asks to define queries for a Books database, including selecting all authors and publishers, selecting books by a specific author or publisher, and inserting new author, publisher, and book records.

Uploaded by

Faisal Shehzad
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/ 3

ASSIGNMENT OF QUERIES

NAME : Kamran Amin


Roll No.: 109-BSCS-2017
Section : A
Submitted To : Maam Asma Kanwal

Department Of Computer Sciences


GC University , Lahore .

(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

b) Select all publishers from the Publishers table.


Sol.
SELECT * FROM PUBLISHERS

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’);

INSERT INTO PUBLISHERS (PUBLISHERS_ID, PUBLISHERS_NAME)


VALUES (005, ‘DOGARPUBLISHERS’);

INSERT INTO BOOKDETAILS (ISBAN, PUBLISHERS_ID, AUTHORS_ID, TITLE, YEAR)


VALUES (0003322555,005,009,’DEWANEGHALIB’,1945);

You might also like