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

Database Concept-SQL

Uploaded by

Aslam Basha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Database Concept-SQL

Uploaded by

Aslam Basha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Database Concept -SQL

Worksheet - 3
SUB: COMPUTER SCIENCE (083)
DATE : 20.9.2024
SNO QUESTIONS
1. ________ command is used to change table structure in SQL.
(A) update (B) change (C) alter (D) modify
2. Which of the following commands will remove the entire database from MYSQL?
(A) DELETE DATABASE (B) DROP DATABASE (C) REMOVE DATABASE (D) ALTER DATABASE
3. The SELECT statement when combined with ________ clause, returns records without repetition.
(A) DISTINCT (B) DESCRIBE (C) UNIQUE (D) NULL
4. Which function is used to display the total number of records from a table in a database?
(A) total() (B) total(*) (C) return(*) (D) count(*)
5. Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your
answer.
6. Differentiate between order by and group by clause in SQL with appropriate example.
7. Categorize the following commands as DDL or DML: INSERT, UPDATE, ALTER, DROP
8. Write the output of the queries (i) to (vi) based on the table given below:

(i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10;
(ii) Select * from CHIPS where FLAVOUR=”TOMATO” and PRICE > 20;
(iii) Select BRAND_NAME from CHIPS where price > 15 and QUANTITY < 15;
(iv) Select count( distinct (BRAND_NAME)) from CHIPS;
(v) Select price , price *1.5 from CHIPS where FLAVOUR = “PUDINA”;
(vi) Select distinct (BRAND_NAME) from CHIPS order by BRAND_NAME desc;
9. (A) Consider the following tables BOOKS and ISSUED in a database named “LIBRARY”. Write SQL commands for
the statements (i) to (iv).
(i) Display book name and author name and price of computer type books.
(ii) To increase the price of all history books by Rs 50.
(iii) Show the details of all books in ascending order of their prices.
(iv) To display book id, book name and quantity issued for all books which have been issued.
(B) Write the command to view all tables in a database.
10. Layna creates a table STOCK to maintain computer stock in vidyalaya. After creation of the table, she has
entered data of 8 items in the table.

Based on the data given above answer the following questions:


(i) Identify the most appropriate column, which can be considered as Primary key.
(ii) If three columns are added and 5 rows are deleted from the table stock, what will be the new degree and
cardinality of the above table?
(iii) Write the statements to:
(a) Insert the following record into the table Stockid - 201, dateofpurchase – 18-OCT-2022, name – neckphone
Make – BoAT, price - 500
(b) Decrease the price of stock by 5% whose were purchased in year 2020
OR (Option for part iii only)
(iii) Write the statements to: (a) Delete the record of stock which were purchased before year 2015. (b) Add a
column STATUS in the table with datatype as char with 1 characters
11. Which of the following statements is True?
a) There can be only one Foreign Key in a table. b) There can be only one Unique key is a table
c) There can be only one Primary Key in a Table d) A table must have a Primary Key.
12. Which of the following is not part of a DDL query?
a) DROP b) MODIFY c) DISTINCT d) ADD
13. _______________ Keyword is used to obtain unique values in a SELECT query
a) UNIQUE b) DISTINCT c) SET d) HAVING
14. Which statement in MySql will display all the tables in a database?
a) SELECT * FROM TABLES; b) USE TABLES; c) DESCRIBE TABLES; d) SHOW TABLES;
15. Which of the following is a valid sql statement?
a) ALTER TABLE student SET rollno INT(5); b) UPDATE TABLE student MODIFY age = age + 10;
c) DROP FROM TABLE student; d) DELETE FROM student;
16. A MySQL table, sales have 10 rows.
The following queries were executed on the sales table.
SELECT COUNT(*) FROM sales;
COUNT(*)
10
SELECT COUNT(discount) FROM sales;
COUNT(discount)
6
Write a statement to explain as to why there is a difference in both the counts.
17. What is the difference between a Candidate Key and an Alternate Key
18. a) Consider the following tables Emp and Dept:
Relation: Emp
What will be the output of the following statement?
SELECT * FROM Emp NATURAL JOIN Dept WHERE dname='Physics';
b) Write output of the queries (i) to (iv) based on the table Sportsclub
Table Name: Sportsclub

(i) SELECT DISTINCT sports FROM Sportsclub;


(ii) SELECT sports, MAX(salary) FROM Sportsclub GROUP BY sports HAVING sports<>'SNOOKER';
(iii) SELECT pname, sports, salary FROM Sportsclub WHERE country='INDIA' ORDER BY salary DESC; (iv) SELECT
SUM(salary) FROM Sportsclub WHERE rating='B';
19. Based on the given set of tables write answers to the following questions.
Table: flights

a) Write a query to display the passenger, source, model and price for all bookings whose
destination is KOL.
b) Identify the column acting as foreign key and the table name where it is present in the given
example.
20. Tarun created the following table in MySQL to maintain stock for the items he has.
Table : Inventory

Based on the above table answer the following questions. a) Identify the primary key in the table with valid
justification.
b) What is the degree and cardinality of the given table.
c) Write a query to increase the stock for all products whose company is Parley.
OR (only for part c)
Write a query to delete all the rows from the table which are not having any rating.
21. All tuples in the relation are assigned NULL as the value for the new Attribute,with the ________ Command
(a) MODIFY (b) TAILOR (c)ELIMINATE (d) ALTER
22. Which of the following ignores the NULL values inSQL?
a) Count(*) b) count() c)total(*) d)None of these
23. Write the output of the queries (a) to (d) based on the table

(a) SELECT min(Population) FROM country;


(b) SELECT max(SurfaceArea) FROM country Where Lifeexpectancy < 50;
(c) SELECT avg(LifeExpectancy) FROM country Where CName Like "%G%";
(d) SELECT Count(Distinct Continent) FROM country;
OR
(a) Identify the candidate key(s) from the table Country.
(b) Consider the table CAPITAL given below:

Which field will be considered as the foreign key if the tables COUNTRY and CAPITAL are related in a database?
24. Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and Posting given below:

1. SELECT count(DISTINCT Address) FROM Consumer;


2. SELECT Company, MAX(Price), MIN(Price), COUNT(*) from Stationary GROUP BY Company;
3. SELECT Consumer.ConsumerName, Stationary.StationaryName, Stationary.Price FROM Stationary, Consumer
WHERE Consumer.S_ID = Stationary.S_ID;
25. (Write a output for SQL queries (i) to (iii), which are based on the table: SCHOOL and ADMIN given below:
i) SELECT SUM (PERIODS), SUBJECT FROM SCHOOL GROUP BY SUBJECT;
ii) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE DESIGNATION = ‘COORDINATOR’
AND SCHOOL.CODE=ADMIN.CODE;
iii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;
26. Write SQL commands for the following queries (i) to (v) based on the relation Trainer and Course given below:

(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of December 2001. (iii) To
display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE of all those courses whose
FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
OR
(iv) To display the Trainer ID and Name of the trainer who are not belongs to ‘Mumbai’ and ‘DELHI’
27. ______ command is used to ADD a column in a table in SQL.
(a) update (b)remove (c) alter (d)drop
28. Which of the following is a DML command?
(a) CREATE (b) ALTER (c) INSERT (d) DROP
29. Which function is used to display the total number of records from a table in a database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
30. (a) Consider the following tables – Sales and Item:

What will be the output of the following statement?


SELECT SNAME,SCITY,IPRICE FROM sales, Item where SCITY=”Delhi” and Sales.SCode =Item.SCode;
(b) Write the output of the queries (i) to (iv) based on the table, TABLE: EMPLOYEE

(i) SELECT AVG(SALARY) FROM EMPLOYEE WHERE CITY LIKE ‘%R’;


(ii) SELECT COUNT(*) FROM EMPLOYEE WHERE DATE_OF_JOINING BETWEEN ‘2011-01-01’ AND ‘2020-12-21’;
(iii) SELECT DISTINCT CITY FROM EMPLOYEE WHERE SALARY >65000;
(iv) SELECT CITY, SUM(SALARY) FROM EMPLOYEE GROUP BY CITY;

You might also like