Database Concept-SQL
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.
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
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:
(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: