12.
13.
14.
15.
16.
17.
Data Management: SQL Commands
➢ Consider the table “student” given below and write the SQL statements for the given
queries.
Rno Class Section Gender Name DOB Marks
1 XI A M Shreyan 2002-05-02 70
2 XI A F Shelly 2003-06-04 72
3 XI B F Palak 2001-02-03 84
4 XI A M Vikalp 2001-03-05 68
5 XI B M Vinit 2004-08-15 62
6 XI B F Khushi 2003-07-12 73
7 XI A F Rahul 2003-08-06 85
8 XI B F Mihir 2005-05-03 81
9 XI B M Tiya 2002-02-02 91
10 XI A M Premanshu 2004-08-03 83
1. To create a database “record”.
ANS.: CREATE DATABASE record;
2. To create student table with the Rno, Class, Section, Gender, Name, DOB, and Marks as
attributes where Rno is the primary key.
ANS.:
CREATE TABLE student(
Rno integer(5) Primary Key,
Class char(4),
Section char(2),
Gender char(3),
Name varchar(20),
DOB date,
Marks integer(10));
3. To insert the details of at least 1 student in the above table.
ANS.: Insert into student values (11, 11, ‘B’, ‘M’, ‘Yuvraj’, ‘2002-04-05’, 65);
4. To display the entire content of table.
ANS.: SELECT * FROM student;
5. To display Rno, Name and Marks of those students who are scoring marks more than 50.
ANS.: SELECT Rno, Name, Marks FROM student WHERE Marks > 50;
6. To find the average of marks from the student table.
ANS.: SELECT AVG(Marks) FROM student;
7. To find the number of students, who are from section ‘A’.
ANS.: SELECT COUNT(*) FROM student WHERE Section = ‘A’;
8. To display the information all the students, whose name starts with ‘AN’ (Examples: ANAND,
ANGAD,..).
ANS.: SELECT * FROM student WHERE Name LIKE ‘AN%’;
9. To display Rno, Name, DOB of those students who are born between ‘2005- 01-01’ and ‘2005-
12-31’.
ANS.: SELECT Rno, Name, DOB FROM student WHERE DOB BETWEEN ‘2005- 01-01’ AND ‘2005-
12-31’;
10. To display Rno, Name, DOB, Marks of those male students in ascending order of their names.
ANS.: SELECT Rno, Name, DOB, Marks FROM student WHERE Gender=’M’ ORDER BY Name
ASC;
11. To display Rno, Gender, Name, DOB, Marks in descending order of their marks.
ANS.: SELECT Rno, Name, DOB, Marks FROM student ORDER BY Name DESC;
12. To display the unique section available in the table.
ANS.: SELECT DISTINCT(Section) FROM student;