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

SQL Practice Questions

This document contains sample SQL practice questions and examples related to SQL commands, database and table structures, data manipulation, and more. Specifically: 1. It provides examples of SQL clauses, operators, functions and commands like ORDER BY, IS NULL, aggregate functions, ALTER, SELECT, INSERT, and more. 2. It describes a sample STORE database with attributes like ItemNo, ItemName, etc and examples of DDL commands to create tables, insert data, and drop tables. 3. It includes questions about concepts like candidate keys, fetch methods, DDL/DML, and using JOINs to query data from multiple tables.

Uploaded by

Tanishq Aryan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views

SQL Practice Questions

This document contains sample SQL practice questions and examples related to SQL commands, database and table structures, data manipulation, and more. Specifically: 1. It provides examples of SQL clauses, operators, functions and commands like ORDER BY, IS NULL, aggregate functions, ALTER, SELECT, INSERT, and more. 2. It describes a sample STORE database with attributes like ItemNo, ItemName, etc and examples of DDL commands to create tables, insert data, and drop tables. 3. It includes questions about concepts like candidate keys, fetch methods, DDL/DML, and using JOINs to query data from multiple tables.

Uploaded by

Tanishq Aryan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL Practice Questions

In SOL, name the clause that is used to


display the tuples in ascending order of an attribute.
2 In SQL, what is the use of IS NULL operator?
3 Write any one
aggregate function used in SQL.
1
4 Which of the following is a DDL command? a) SELECT b) ALTER c) INSERT d) UPDATE 1
5 In SQL, write the query to display the list of tables stored in a database. 1
6 Which of the following types of table constraints will prevent the entry of duplicate rows? 1
a) Unique b) Distinct c) Primary Key d) NULL
A departmental store
MyStore is considering maintaining their inventory using SQL to store the data. 5
As a database administer,
Abhay has decided that
Name of the database mystore Name of the table
-

STORE
The attributes of STORE are as follows:
ItemNo numeric, ItemName - character of size 20, Scode numeric,
-

Quantity numeric
-

Table:STORE (a) ldentify the attribute best suitable to be


ItemNo ItemNamne Scode Quantity declared as a primary key,
2005 Sharpener Classic 23 60 (b) Write the degree and cardinality of the table
2003 Ball Pen 0.25 22 50
STORE.
2002 Get Pen Premium 21 150
2006
(c) Insert the following data into the attributes
Get Pen Classic 21 250
2001 ItemNo, ItemName and SCode respectively in
Eraser Small 22 220
2004 Eraser Big the given table STORE. ItemNo =
2010,
22 110
2009 ItemName = "Note Book" and Scode 25;
Ball Pen 0.5 21 180

[d) Abhay want to remove the table STORE from the database MyStore. Which command will he use
from the following:
a) DELETE FROM store; b) DROP TABLE store;
c) DROP DATABASE mystore; d) DELETE store FROM mystore;
(e) Now Abhay wants to display the structure of the table STORE, i.e, name of the attributes and their
respective data types that he has used in the table. Write the query to display the same.

8 What do you understand by Candidate Keys in a table? Give a suitable example of Candidate Keys 2
from a table containing some meaningful data.
9 Differentiate between fetchone() and fetchal) methods with suitable examples for each. 2
10 Write the full forms of DDL and DML. Write any two commands of DML in SQL. 2
11 Write the outputs of the queries (i) to (ii) based on the relations Teacher and Posting given below: 3
Table Teache Table: Posting
T_ID Name Age Department Date_o join | Salary Gender
ID Department Place
1 Jugal 34 Computer Sc 10/01/2017 | 12000 M
1 History Agra
2 Sharmila 31 History 24/03/2008 20000F Mathematics Raipur
3 Sandeep 32 Mathematics 12/12/2016| 30000 M
Computer Science Delhi
4 Sangeeta 35 History 01/07/2015 40000F
5| Rakesh 42 Mathematics 05/09/2007 25000 M

6 Shyam 50 History 27/06/2008|30000 M


7 Shiv Om| 44 Computer Sc 25/02/2017|21000 M
8 Shalakha 33
Mathematics 31/07/2018 20000 F
SELECT Department, count(") FROM Teacher GROUP BY Department;

hl SELECT Max(Date_ofJoin).Min(Date_of_Join) FROM Teacher;


c SELECT Teacher.name,Teacher.Department, Posting.Place FROM Teachr, Posting WHERE
Teacher.Department = Posting.Department AND Posting.Place="Delhi";

sQL commands for the following queries () to (v) based on the relations Teacher and Posting 5
12 Write
given below:

Table: Teacher Table Posting


T_ID Name Age Department Date_of_join Salary Gender P_1D Department Place
Computer 10/01/2017 12000 M History Agra
1 Jugal 34
Sc
2 Mathematics Raipur
Sharmila 31 History 24/03/2008 20000 F Computer Science Delhi
3 Sandeep 32 Mathematics 12/12/2016 30000 |M
4 Sangeeta 35 History 01/07/2015 40000F
5 Rakesh42 Mathematics 05/09/2007 25000 M
6 Shyam 50 History 27/06/2008 30000 M

7 Shiv Om 44
Computer
25/02/2017 21000 M
Sc
Shalakha 33 Mathematics 31/07/2018 20000 F

i. To show all information about the teacher of History department.


i. To list the names of female teachers who are in Mathematics department
ii. To list the names of all teachers with their date of joining in ascending order.
iv. To display teacher's name, salary, age for male teachers only.
v. To display name, bonus for each teacher where bonus is 10% of salary.

You might also like