You are on page 1of 2

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

DBMS Lab (PCS-503), B. Tech., CSE, 5th Sem.

 MODULE 2

#Problem statement 2- Consider the given relational schema.

Student(Roll_No, Name, Marks, City, Gender, Branch)

(a) For the above schema, set the data types along with constraints as per the following.
(Hint: You need not modify the schema of a table for this; you only need to define the given
data types with constraints (if any) at the time of the table's creation.)

1. For Roll_No field, set the data type as an Integer with PRIMARY KEY constraint. Moreover,
this field is auto-incremented. i.e., it will set the Roll_No. automatically from 1 to 5. You need
not insert any value in this field manually.
2. For Name field, set the data type as VARCHAR(20) with NOT NULL Constraint.
3. For Marks field, set the data type as an Integer with ‘CHECK’ constraint where marks (>=65
and <=90)
4. For City field, set the data type as VARCHAR(20).
5. For Gender field, set the data type as VARCHAR(20) with NOT NULL constraint.
6. For Branch field, set the data type as VARCHAR(20).

(b) By using the above schema perform the following SQL Queries.
1. Write a SQL query to insert the following into the table.
Roll_No Name Marks City Gender Branch
1 AJAY 70 Dehradun Male CSE
. VIVEK 65 Delhi Male CSE
. SIMMY 90 Dehradun Female ME
. MATT 76 Dehradun Male ECE
5 REENA 80 Mumbai Female CSE

2. Write a SQL query to find the number of students gender-wise.


3. Write a SQL query to find the number of students Branch-wise.
4. Write a SQL query to find the average age of male and female students.
5. Write a SQL query to find the branches in which students are more than one.
6. Write a SQL query to find the branches having only one student.
7. Write a SQL query to display all the students who do not belong to the city 'Dehradun'.
8. Write a SQL query to display the student details where name of the City of the student is
ending with character ‘i’.
9. Write a SQL query to display the starting 3 rows from the table.
10. Write a SQL query to update the name of a student from ‘REENA’ to ‘DEEPTI’.

You might also like