SQL ( Class XII ) Revision Boards -2025
(Important questions)
1. What is the difference between DDL and DML commands?
Ans :
DDL DML
1.DDL stands for data definition language 1.DML stands for data manipulation
language
2. DDL is used to specify database 2. DML is used to access or modify the data
scheme/structure in the table
3. DDL affects the database or table 3. DML commands affects the one or more
records in a table
4. Example 4. Example
1. create table 2. Alter table 3. Drop table 1. select 2. Insert 3. Update 4. Delete
2. What is the difference between char and varchar data type?
Ans :
Char Varchar
1. It is a fixed length character data type 1. It is a variable length character data type
2. by default char size is 1 2. It is compulsory to give the size if we try
to skip . then it will result in error
3. Storage size of char data type is euql to n 3. Storage size of varchar data type is equal
bytes to the actual length of the entered string in
bytes.
4. In char, if the length of string is less than 4. In varchar, if the length of string is less
set or fixed length then it is padded with than set or fixed length then it will store as
extra memory spaces. it is without padded with extra memory
space.
5. It can hold maximum 255 character 4. It can hold maximum 65,535 character
3. What is the difference between drop or delete commands?
Ans :
DROP DELETE
1. DROP is used to delete a entire table 1. It is used to delete one or more row
including structure based on the condition. It will not delete
the structure of table.
2. Drop is a DDL command. 2. Delete is a DML command
3. syntax is DROP table table name ; 3. Syntax is Delete from tablename;
4. What is the difference between order by and group by in sql ?
Order by Group by
1. It is used to display the information 1. It is used to group the data on the basis
either in ascending order or in descending of particular column
order 2. It is mandatory to use aggregate function
in order to use group by command.
2. It is not mandatory to use aggregate 3. Example select * from student group by
function in order to use order by command. stream’
Ex: select * from student order by rno;
4. What is the difference between where and having?
Where Having
1. The where clause specifies a criteria 1. The having clause cannot be used
which individual record must meet It can be without the group by command.
used with group by clause 2. The having clause selects rows after
2. where clause select rows before grouping grouping.
Ex : select * from student where marks >40; Ex: select * from student group by stream
having max(marks)>40;
5. What is the difference between alter and update command ?
Alter Update
1. Alter command is used to add , delete , 1. update command is used to modify the
modify the column from the table values from tables.
2. Alter is the DDL commands. 2. Update is the DML commands
3. Ex : alter table student add 3. Ex : update student set marks=50 where
column(gender char(2)); rno=4
2. Describe the following-
1. data model – it is a concept to describe the structure of table with certain constraints.
2. Relational data model – data is organized into tables . These tables are called relation.
3. Relation – A table storing data containing row and colums.
4. Domain – A pool of values from which the actual values appears in particular row and
column .
5. Tuple – A row in a relation is called tuple. It is also called record.
6. attribute – A column in a relation is called attribute.
7. Cardinality – total no of records or tuples in a table is called cardinality.
8. Degree – Total number of column in a relation is called degree.
9. View – A virtual table that does not exist but derived from another table.
10. Primary key – A field or set of field that uniquely identifies the tuple is called primary
key. In a student table rollno is primary key.
11. Candidate key – In a table , there are more than one key can describe a table . Those
keys are known are candidate keys. In a student table ( rno, name, clas, marks, regno) ,In
which rno and regno is candidate key . One of the candidate key becomes a primary key
12. Alternate key – In a table there are more than one candidate key one of the candidate
key becomes a primary key , the left one is called alternate key . In a student table there
arerno and regno are candidate keys . Rno is primary key then regno is alternate key.
13. Foreign key – It is a non key attribute, which comes from another table. Whose value is
derived from another table primary key. It is called foreign key. In a student table ( rno,
name, clas, marks, tno) , teacher(tno, tname, exp) . In teacher table tno is primary key and
in student table tno is foreign key.
14. Referential integrity – It is a system of rules in database management system . It
ensures the relationship between records in related tables are valid. User don’t accidently
delete or change related data.
3. Data types – It is used to identify the data and associated operations .
Data type Type Size
Char String 0-255 char
Varchar String 0-255 char
Text String (tiny text, medium
text, long text)
Int Integer ( tiny int, small int,
medium int, bigint)
Float Decimal Praise 23 to 53 digits
Double Decimal Praise 24 to 53 digits
Decimal Double stored as string
Date yyyy-mm-dd It is denoted in ‘’
Time HH:MM:SS
Datetime Yyyymmddhhmmss
Boolean Tiny int 1
4. describe the following operations –
a) create database - ( sql command ) create database toy; ( toy is database name)
b) access database - use toy ;
c) write a query create table employee The fields are ecode integer size 3, ename
alphabet 25, sex char one , grade char 2 gross is decimal
ans : create table employee (ecode int(3), ename char(25), sex char, grade char(2), gross
decimal);
d) c) write a query create table employee The fields are ecode integer size 3, constraint is
primary key and not empty , ename alphabet 25 no duplicate value, sex char one , grade
char 2 gross is decimal not more than 5000
ans : create table employee (ecode int(3) primary key not null , ename char(25) unique , sex
char, grade char(2), gross decimal check gross <5000);
Hint – constraints are the rules applied to fields.
1. not null contraints – It ensure that field or column has no null value
2. default – It provides default value to column when none is specified
3. unique – Ensure all values in a field or column is different.
4. check – It ensure that all values in a column satisfy the following criteira
5. Primary key – It is used to uniquely identify the row in a table
6. Foreign key – It ensures the referential integrity .
Ex Write a query to create a table student the description is given below- Table name is
product.
FIELD TYPE SIZE CONSTRAINTS
Pno Integer 3 Primary key not
empty
Pdate Date 8
Pname Alphabet 25 No duplicate
Stock Integer 4 Less than 5000
Customer_id Integer 4 Foreign key from
table customer
primary key cid
Ans :
Create table product (pno int(3) primary key not null, pdate date, pname char(25) unique,
stock int(4) check stock <5000,foreign key (customer_id) references customer(cid);
e) To add a new column ( field) to the table - Alter command is used . There are 2 options
add, modify
ex. Write a query to add new field grade to product table whose data type is char and size
is 1.
Ans: alter table product add(grade char);
Ex: Write a query to modify existing field pname whose size is changes from 25 to 20
Ans : alter table product modify(pname char(20));
f) in a product table
Pno Pname Pdate Stock City Tno
AB101 MANGO 19-07-2009 500 KANPUR A101
CD102 BANANA 22-03-2008 700 DELHI A101
AB103 ORANGE 08-03-2007 300 KANPUR A102
CF103 GRAPES 06-12-2008 600 LUCKNOW A103
AM302 APPLE 08-12-2007 500 NULL A104
Transaction table
Tno Tname grade
A101 RAMESH GUPTA A
A102 SAUMYA B
A103 NITIN C
A104 SULEKHA A
SQL query
1)Display and select all data from product table - select * from product;
2) display only product no and product name from table – select pno , pname from product;
3) Display those product who belongs to Kanpur city ( condition) – select * from product
where city =’KANPUR’;
4) Display cities but city name is not duplicate from product table - select distinct city from
product;
5. Display and count how many cities are stored in product table – select count(distinct city)
from product.
6. Display those product whose stock is in the range of 300 to 700 – select * from product
where stock <=300 and stock >=700; ( both values are included )
7. Display those product whose stock is in the range of 300 to 700 using between clause –
select * from product where stock between 300 and 700; ( both values are included )
8. Display the structure of product table - describe product;
9. What is output - select getdate() → todays date in the format of yyyy-mm-dd (2025-
03-28)
10. what is output – select 2+3*4 ( use bodmas) →14
11. Display those records who belongs to either Kanpur , delhi or lucknow - select * from
product where city in (‘KANPUR’,’DELHI’,’LUCKNOW’);
12. insert the following record in product table (AG104,PAPAYA,28-03-2025,800,GONDA)
Insert into product values(‘AG104,’PAPAYA’,’2025-03-28’,800,’GOLDA’);
13. Display those records from product table whose second character of pno is ‘B’
Ans : HINT – We are using wild card operator with like . There are 2 wild card operator
a) % - represents left characters b) _(underscore) – represent a single character.
Select * from product where pno like ‘_B%’;
14. Display those records from product table whose pno is 5 character long .
Ans : select * from product where pno like ‘_ _ _ _ _’;
15. Display those product from product whose city is null
Ans : select * from product where city = NULL; or city is NULL
16. Display those product from product whose city is not null
Ans : select * from product where not city = Null
17. Write a query to Delete all product from product table
Ans : delete from product;
18. Write a query to delete all product from product table whose city is KANPUR
Ans : delete from product where city =’KANPUR’;
19. increase stock by 2% in product table
Ans : update product set stock = stock + (stock *0.02) ;
20. decrease stock by 5% in product table for city is DELHI
Ans: update stock set stock =stock –( stock *0.05) where city = ‘DELHI’;
21. Write a query to display product no ,product name, stock , amount where amount is
stock *2 and display under field heading “amount”
Ans : select pno ,pname, stock , stock *2 as “ amount” from product ;
22. Display the details of product sorted by product no in ascending order .
Ans : select * from product order by pno asc;
23. Display product no , name , stock from product table sorted by product no in
descending order.
Ans : selectr pno , pname , stock from product order by pno desc;
24. create a temporary table temp which select those product whose stock is more than 300
Ans : create view temp as select * from product where stock >300;
25. Describe aggregate function ?
Ans : it is a group function or aggregate function which works upon group of row or multiple
rows.
Avg()- select avg(sal) from emp; count()- select count(*) from product;
Max() - select max(sal) from emp; min()- select min(sal) from emp; sum()- select sum(sal)
from emp;
26 (special) display total no of records from product table
Ans : select count(*) from product;
27.(special) Display those records from product table , city wise whose total no of records
are less than 4
Ans : select * from product group by city having count(*) <4;
28. What is the output of the following a) select count(job) from product;
Count(job)
04 ( null value is not included)
29. Join operation – A join is the query that combines rows from two tables. In join query
more than one tables are listed in from clause.
There are 2 types of join a) equi join b) natural join
a) equi join – equi join performs a join against equality or matching columns between
associated tables. You can also perform equi join by using join keyword followed by on
keyword and then specifying names of the column along with their associated tables to
check equality
Ex( sure short) Display product no , product name , stock , transaction no , transaction
name, grade from product and transaction table
Ans : select product.pno,product.pname, product.stock ,transaction.tno, transaction.tname,
transaction.grade from product,transaction where product.tno = transaction.tno;
Or
Ans : select p.pno,p.pname, p.stock ,t.tno, t.tname, t.grade from product p,transaction t
where p.tno = t.tno;
Ex( sure short) Display product no , product name , stock , transaction no , transaction
name, grade from product and transaction table whose city is Delhi
Ans : select product.pno,product.pname, product.stock ,transaction.tno, transaction.tname,
transaction.grade from product,transaction where product.tno = transaction.tno and
product.city=’DELHI’;
Natural join - It is a type of equi join and is structured in such a way that, columns with the
same name of associated tables will appear once only.
Cartesian product – It is a multiplication of one table with another . It is denoted by ‘x’.
Table :A Table : B
PNO PNAME STOCK
101 ABC 500 TNO TNAME
102 XYZ 200 401 ALOK
103 MNP 100 402 ABHIK
403 SURBHI
Q: Write a query to find the cartesian product of A and B .
Ans : Select * from A, B;
OUTPUT
PNO PNAME STOCK TNO TNAME
101 ABC 500 401 ALOK
102 XYZ 200 401 ALOK
103 MNP 100 401 ALOK
101 ABC 500 402 ABHIK
102 XYZ 200 402 ABHIK
103 MNP 100 402 ABHIK
101 ABC 500 403 SURBHI
102 XYZ 200 403 SURBHI
103 MNP 100 403 SURBHI
~~~~~~~~~~~~`