0% found this document useful (0 votes)
30 views6 pages

Small Questions

This document contains examples of SQL commands and questions about SQL. It provides sample SQL queries to retrieve data from tables based on various conditions, perform aggregation, data modification operations like insert, update, delete etc. It also includes examples of DDL commands to create, alter and drop tables and databases.

Uploaded by

Paranjay Das
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)
30 views6 pages

Small Questions

This document contains examples of SQL commands and questions about SQL. It provides sample SQL queries to retrieve data from tables based on various conditions, perform aggregation, data modification operations like insert, update, delete etc. It also includes examples of DDL commands to create, alter and drop tables and databases.

Uploaded by

Paranjay Das
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/ 6

1.Which of the following is DDL command?

-INSERT INTO

-UPDATE

-ALTER

-SELECT

-WHERE

-ROLL BACK

2.Which of the following sets condition on a field?

-PRIMARY KEY

-FOREIGN KEY

-CHECK

-UNIQUE

-DEFAULT

3.Which of the following will not allow a field to take duplicate value and null value?

-PRIMARY KEY

-UNIQUE

NOT NULL

-FPOREIGN KEY

4.Which of the following will display unique value from a mentioned field?

-PRIMARY KEY

-UNIQUE

-ALL

-DISTINCT

5.Which of the following use wild card characters to match given pattern on a field to display

Records?

-BEWTEEN

-IN

-LIKE

-ORDER BY

6.Which of the following is used in join operation?

-DELETE

-INSERT

-UPDATE
-ALL

7.Which is used for pattern matching condition?

-BETWEEN

-HAVING

-LIKE

-GROUP BY

-IN

-DISTINCT

8.Which of the following is correct for HAVING clause?

-used for all columns rather than groups in table

-used for groups than rows in table

-used for rows than columns in table

-does same as of WHERE clause

9.Which of the following command is used with ALTER command to change the datatype of a field?

-ADD -MODIFY -CHANGE -DROP

Which of the following command is used with ALTER command to rename a field?

-ADD -MODIFY -CHANGE -DROP

Which of the following command is used with ALTER command to include a field in a table?

-ADD -MODIFY -CHANGE -DROP

10.Which command deletes all records from a table?

-DROP -DELETE -TRUNCATE -REMOVE

11.The output will contain all pair of tuples from two tables/relations in which of the following operation?

-Cartesian product

-Join

-Intersection

-Set difference

-All

12.Which command is used to set condition for all records/tuples?

-WHERE (for all records)

Which of the following command is used to set condition for group of records/tuples?

-HAVING (for group(s))

13.Which of the following command is used to set condition for list of values specified?

-WHERE
-HAVING

-IN

LIKE

-BETWEEN

14.ITEM(NO.,ITEM_NAME,TYPE,DATE_STOCK,PRICE,DISCOUNT)

14(i)-show max, min price, total no. of items of each type of items from ITEM table

SELECT MAX(PRICE),MIN(PRICE),COUNT(*),TYPE

FROM ITEM

GROUP BY TYPE;

14(ii)-DISPLAY NAME,ID,DISCOUNT OF ITEM PRICE BETWEEN 13500 TO 14300

SELECT ITEM_NAME, NO., DISCOUNT

FROM ITEM

WHERE PRICE BEWEEN 13500 AND 14300;

ITEM(NO.,ITEM_NAME,TYPE,DATE_STOCK,PRICE,DISCOUNT)

14(iii)-Display proper cost of each item

SELECT PRICE-DISCOUNT AS PROPER_PRICE

FROM ITEM;

15.MEDICAL_OFFICER(ID, NAME, DEPARTMENT, GENDER, EXP)


15(i)-Display max, min exp and total no. of doctors of each department

SELECT MAX(EXP),MIN(EXP),COUNT(*),DEPARTMENT

FROM MEDICAL_OFFICER

GROUP BY DEPARTMENT;

15(ii)-Display number of genders from the table

SELECT COUNT(DISTINCT(GENDER))

FROM MEDICAL OFFICER;

15(iii)-Display doctors details who are in ‘ENT’ or ‘CARDIAC’ or ‘LUNG’ department

SELECT *

FROM MEDICAL_OFFICER

WHERE DEPARTMENT IN(‘ENT’,‘CARDIAC’,‘LUNG’);


16.Write SQL code:

(i) to change datatype of field E_Name from char(50) to varchar(70) in Employee table

ALTER TABLE Employee

MODIFY E_Name varchar(70);

(ii)to rename a field E_Sal to Salary_Month in Employee table

ALTER TABLE Employee

CHANGE E_Sal Salary_Month int;

(iii)to insert 3 records in WORKER table, the table is containing following specifications:

(W_ID char(10) , W_NAME varchar(70) , W_SAL integer ,W_DEPT char(20) , W_AREA varchar(80) , W_AGE integer)

INSERT INTO WORKER

VALUES(‘101’ , ’JOHN’ , 13700 , ‘PRODUCTION’ , ‘DELI’ , 29),

(‘102’ , ‘DAVID’ , 14500 , ‘R&D’ , ‘KARNATAKA’ , 29),

(‘103’ , ’JOHN’ , 13700 , ‘PRODUCTION’ , ‘DELI’ , ‘MUMBAI’)

(iv)to display pension of every month which is 3700+27% of worker salary

consider the following Worker table:

(W_ID char(10) , W_NAME varchar(70) , W_SAL integer ,W_DEPT char(20) , W_AREA varchar(80) , W_AGE integer)

SELECT W_SAL*(27/100)+3700 AS PENSION

FROM Worker;

17.Write SQL code to create a database WORKINGZONE

CREATE DATABASE WORKINGZONE;

18.Display list of tables inside WORKINGZONE database

SHOW TABLES;

19.To delete all the records from table STUDENT

TRUNCATE TABLE STUDENTS;

20.to display list of databases in RDBMS such as SQL Server

SHOW DATABASES;

21.To display structure of table Student

DESC Student;

Or

DESCRIBE Student;

22.Consider the following tables:

EMPLOYEE(E_ID,F_NAME,L_NAME,LOCATION,CITY)

POST(E_ID,E_SAL,E_BONUS,E_POST)
(i)to display first name, location of employees who are coming from ‘DELHI’ or ‘PUNE’ or ‘BENGALURU’

SELECT F_NAME,LOCATION

FROM EMPLOYEE

WHERE CITY IN(‘DELHI’, ‘PUNE’, ‘BENGALURU’);

(ii)to display details of employee whose name starts with ‘A’ from EMPLOYEE table

SELECT *

FROM EMPLOYEE

WHERE F_NAME LIKE “A%”;

(iii)to display max salary, min salary, max bonus, no. of employees of each department/post from

EMPLOYEE table

SELECT MAX(E_SAL),MIN(E_SAL),MAX(E_BONUS),COUNT(*),E_POST

FROM EMPLOYEE

GROUP BY E_POST;

23,Consider the following table:

CLOTHES(CODE,NAME,PRICE,LAUNCHDATE)

(i)to display details of clothes which was launched after 2005(assume that all launch dates are given with 2005,2006)

SELECT *

FROM CLOTHES

WHERE LAUNCHDATE LIKE “%6”;

(ii)to display name,price,discount which is 25% of price

SELECT NAME,PRICE,PRICE*(25/100) AS DISCOUNT

FROM CLOTHES;

(iii)to display all information of clothes in ascending order of name where price is more than 430 rupees

SELECT *

FROM CLOTHES

WHERE PRICE>430

ORDER BY NAME; or ORDER BY NAME ASC;

24.Write SQL code to delete a field B_GROUP From a table STUDENT

ALTER TABLE STUDENT

DROP B_GROUP;

You might also like