0% found this document useful (0 votes)
39 views4 pages

CH2-Relational Data Model

The document discusses relational data models and contains multiple questions related to SQL queries. It provides the questions, expected answers, and sample SQL queries to retrieve, insert, update, and delete data from relational database tables. The questions cover concepts like creating and renaming tables, arithmetic and logical operators, normalization, database administrator responsibilities, and more advanced SQL queries involving joins, aggregation, and sorting.

Uploaded by

shree500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

CH2-Relational Data Model

The document discusses relational data models and contains multiple questions related to SQL queries. It provides the questions, expected answers, and sample SQL queries to retrieve, insert, update, and delete data from relational database tables. The questions cover concepts like creating and renaming tables, arithmetic and logical operators, normalization, database administrator responsibilities, and more advanced SQL queries involving joins, aggregation, and sorting.

Uploaded by

shree500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2-Relational Data Model

Q: 2 Marks Question:

1. Write syntax for creating and Renaming a table.


2. Enlist arithmetic and logical SQL operators.

Q: 4 Marks Question:

1. State and explain 2NF with example.


2. Describe any four responsibilities of Database Administrator.
3. I) Create table Student (S_id, S_name, S_addr, S_marks) with proper data type and size.
Ans : Create table Student(S_id int primary key, S_addr varchar(20) ,S_marks float);

ii) Insert row (5, ‘ABC’, ‘RRRRR’, 79) into student table.

Ans: Insert into Student values (5,’ABC’,’RRRRR’,79);

iii) Update marks of student 85 where S_id is 5.

Ans: Update Student Set marks=85 where S_id=5;

Q: 6 Marks Question:

1. Consider the table Student (name, marks, dept, age, place, phone, birthdate) Write SQL query
for following :
(i) To list students having place as ‘Pune’ or ‘Jalgaon’.

Ans : select * from Student where Place=’Pune’ or ‘Jalgaon’;

(ii) To list students having same department (dept) as that of ‘Rachana’.


(iii) To change marks of ‘Rahul’ from 81 to 96.

Ans : Update Student set marks=96 where name=’Rahul’.

(iv) To list student name and marks from ‘Computer’ dept.

Ans : Select name ,marks from Student where dept=’Computer’.

(v) To list student name who have marks less than 40.

Ans: select name from student where marks<40.

(vi) To list students who are not from ‘Mumbai’.

Ans : select * from student where place Not In (‘Mumbai’);

2. Write SQL queries for following. Consider table stud (roll no, name, subl, sub2, sub3).

(i) Display names of students who got above 40 marks in sub2.

Ans : Select name from Stud where sub2>40;


2-Relational Data Model

(ii) Display names of students whose name start with 'A' by arranging them in ascending order of
subl marks.

Ans : select * from stud where name like ‘A%’ order by sub1;

(iii) Display student name whose name ends with h' and subject 2 marks are between 60 to 75.

Ans : select name from stud where name like ‘h%’ and Between 60 and 75.

(iv) Display names of student who got minimum mark in subl.


Ans : select name from stud where sub1=(select min(sub1) from stud);

3. Consider the following table employee (Emp_id, Emp_name, Emp_age)

Display details of employees whose age is less than 30.

Ans : select * from employee where Emp_age <30.

Display details of employees whose age is in between the range 30 to 60.

Ans : select * from employee where Emp_age Between 30 and 60.

Display names of employees whose name starts with 'S'.

Ans : select Emp_name from employees where Emp_name like ‘S%’;

Display details of employees whose name end with 'd'.

Ans : select * from employees where Emp_name like ‘%d’;

Display details of employees whose age is greater than 50 and whose name contain 'e'.

Ans : select * from employees where age>50 and Emp_name like ‘%e%’;

4. Consider the following database


Employee(emp_id,emp_name,emp_city,emp_addr,emp_dept,join_date)
(i) Display the emp_id of employee who live in city ‘Pune’ or ‘Nagpur’.

Ans: select emp_id from Employee where emp_city=’Pune’ or emp_city=’Nagpur’

(ii) Change the employee name ‘Ayush’ to ‘Ayan’.

Ans: Update Employee set emp_name=’Ayan’ where emp_name=’Ayush’

(iii) Display the total number of employee whose dept is 50.

Ans : Select count(*) from Employee where emp_dept=50


2-Relational Data Model

5. Write a command to crate table student (rollno, Stud_name, branch, class, DOB, City,
Contact_no) and

Ans : SQL>Create table student( Rollno number(5), Stud_name char(10, branch varchar(10), class
varchar(10), DOB date, city varchar(15), Contact_no number(12) );

write down queries for following:

(i) Insert one row into the table

Ans : SQL>Insert into student values(1,‟Ram‟,‟CO‟,‟FirstYear‟,‟12- jun-2001‟,‟Pune‟,98576867) ;

(ii) Save the data

Ans : SQL> commit;

(iii) Insert second row into the table

Ans : SQL>Insert into student values(2,‟Raj‟,‟CO‟,‟FirstYear‟,‟22-Sep2002‟,‟Mumbai‟,98896863);

(iv) Undo the insertion of second row.

Ans : SQL> rollback;

(v) Create save point S1.

Ans : SQL>Savepoint s1;

(vi) Insert one row into the table.

Ans : Insert into student values(3,‟Beena‟,‟CO‟,‟FirstYear‟,‟30- Dec-2002‟,‟Mumbai‟,97846455);

6. Consider following schema: EMP (empno, deptno, ename, salary, designation, join_date, DOB,
dept_location).
Write down SQL queries for following:

(i) Display employees name & number in decreasing order of salary.

Ans : SQL> select ename,empno from EMP order by salary desc;

(ii) Display employee name & employee number whose designation is Manager.

Ans : SQL> select ename,empno from EMP where designation=‟Manager‟;

(iii) Display total salary of all employees.

Ans : SQL> select sum(salary) from EMP ;


2-Relational Data Model

(iv) Display employee names having deptno as 20 and dept_location is Mumbai

Ans : SQL> select enamefrom EMP where deptno=20 and dept_location=‟Mumbai‟;

(v) Display name of employee who earned lowest salary.

Ans : SQL> select ename from EMP where salary=(select min(salary) from EMP);

You might also like