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

Maharishi International Residential School 083 Computer Science - Worksheet On SQL Commands

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Maharishi International Residential school

083 Computer Science – Worksheet on SQL commands


Date of issue: 12.7.24 Date of submission: 15.7.24
TOPIC:alter table (add and remove an attribute, add and remove primary key), drop table, insert,
delete, select,operators (mathematical, relational and logical), aliasing, distinct clause, where clause,
in, between, order by,meaning of null, is null, is not null, like, update command, delete command

QUESTIONS
1 Which command of SQL is used to change/modify the structure of a table?
2 Ms. Shruti has created a table GAMES having attributes ID, GAME, NO_OF_PLAYERS. Later she
wants to add a new attribute DURATION of integer type in this table. How can she do this?
Write down a full command.
3 A table TEACHER has attributes CODE, NAME, POST, CATEGORY. Write down command to
delete the attribute CATEGORY from this table.
4 A table TEACHER has no primary key. Which command will be used to make one if its
attribute named CODE its primary key?
5 What will happen if following command is executed : -
ALTER TABLE EMPLOYEE DROP PRIMARY KEY;
6 Differentiate ALTER TABLE and UPDATE command?
7 While working in MySql Mr. Hitesh wants to delete an existing table MEMBER, but he is
confused between DELETE and DROP TABLE commands. Help him to choose the correct one
out of the following commands: -
DROP TABLE MEMBER;
DELETE FROM MEMBER;
8 What is the purpose of IS NULL and IS NOT NULL operators?
9 What is the use of LIKE operator in SQL?
10

11 What do you mean by the term alias in SQL? Explain briefly by an example? 2
12 Write the name of any two commands under DDL and DML each ? 2
13

a. SELECT PNAME, GAME FROM PLAYER WHERE GENDER=”F”;


b. SELECT DISTINCT GAME FROM PLAYER;
c. SELECT PID,PNAME,RANK FROM PLAYER WHERE GAME=”CRICKET” ORDER BY RANK;
d. SELECT * FROM PLAYER WHERE GENDER<>”M” AND RANK<10;
14

a. SELECT NO,CNAME FROM COACH WHERE GAME IS NULL;


b. SELECT CNAME FROM COACH WHERE GAME LIKE “T%”;
c. SELECT CNAME,GAME, FEE FROM COACH WHERE FEE BETWEEN 51000 AND 100000;
d. SELECT * FROM COACH WHERE GAME IN (“CRICKET”,”BOXING”);
15 Write the queries (a) to (d) based on the table, PLAYER given below:
a. Display details of all male employees
b .Display player name and game whose rank is 5 to 10
c. Show PID PName and rank whose game is either Tennis or Cricket.
d. Add a new record in the table (“P06”, ”Abhinav”,”M”,”Shooting”,1)
Q.16 & 17Write the queries (a) to (d) based on the table BOOK given below:

a. Display details of the books whose price not mentioned


b. Display title and date of purchase of the books having “IP”in their title.
c. Display all the details of books by NCERT in the descending order of their price.
d. Add Rs. 50 in the price of all the books by CBSE.
17a. Display details of the books which have been purchased before 01-01-2022
b. Display BNO, TITLE and PRICE of books which book no is P01, P03 or P05.
c. Delete all the books whose price is not given.
d. Increase the price of all the books by 10% whose price is below 300.
18 Consider the given table Employee and answer the questions given below:

1. To display the details of the Employee whose price is in the range of 5000 to 10000(Both values
included).
2. To increase the salary of Employee by 20% as a bonus.
3. To list the names of those employees who belong to city jaipur,delhi,sikar.
4. To display unique city from a table Employee.
5. Add a new record in above table with the following data:(8,rehan,delhi,3-4-2006,4000)
6. To arrange records in descending order of name.
7. List the names of employees whose salary is more than 200000 and less than 300000.
8. In above table Ram has forgotten to define primary key.Now he wants to define
primary key in the above table.Help ram to write command to make Emp_ID as primary key.
9. Mr. Ram wants to remove the above table with its structure.Help ram to write
command to remove above table.
10. Mr.Harish has left the company.Kindly remove his record from the above table.
In the above table Emp_ID is the primary key.Now Mr ram wants to remove this
constraint. Help ram to write commands for the same.
11. Display the name of an employee whose salary is not defined yet.
12. Mr.Ram wants to give salary rs 5000 to those employees whose salary is not defined
yet.Ram has written the following query:
13. Update Employee Set Salary=5000 having Salary is not NULL
14. Display the names of employee whose city name is of 4-character long.
Q.19 Consider the given table Player and answer the questions given below:

1. To display the details of Players who scored centuries in ascending order of their name .
2. To increase the salary of Player by 50% if he scored a century.
3. To list the names of those Players whose name length is 5 characters and end with 'ESH' .
4. To display unique city from table Player.
5. add a new record in above table with the following data: (8,piyush,kota,90,14000)
6. List the names of Players who belong to city jaipur or tonk.
7. Mr. Ram wants to add one more column "coach_name" .Help ram to write commands .
8. To Display records in descending order of Salary.
Q. 20 What is the Cartesian product of two tables? 2
Q. 21 What is the difference between where clause and having clause? 1
Q. 22 What is equi join? Explain with suitable example. 2
Q. 23 Answer the following questions based on table CUSTOMER and ORDER.

(i) Which column can be most suitable to set as a primary key in table customer with suitable
explanation?
(ii) Ram wants to set CUSTOMER_ID as a foreign key in table ORDER. But he is facing some
problem. Help Ram to remove discrepancy if any that restrict CUSTOMER_ID to act as a foreign
key. Note:(Primary Key in table CUSTOMER:ID, Primary Key in table ORDER:ORDER_ID)

You might also like