10
Q3.Create following two tables including integrity constraints using SQL Command: Table Name : Student Field Name Data Type Field Size Constraints Roll No Number 8 Primary Key Name Text 20 Not Null Address Text 50 Table Name : Enrollment Field Name Data Type Field Size Constraints Roll No Number 8 Foreign Key, Primary Key Course Text 20 Primary Key Grade Text 1 ‘A’,’B’,’C’,’D’,’E’ Perform the following operations using SQL Commands (i) List all the Students enrolled for ‘BBA’ and have grade ‘A’ (ii) Find the number of students enrolled in each course. Ans:- create table student2 (rollno number(8) , name varchar2(20) NOT NULL, address varchar2(50)); Output :- 1

Dbms Practical

Embed Size (px)

DESCRIPTION

dbms

Citation preview

Page 1: Dbms Practical

Q3.Create following two tables including integrity constraints using SQL Command:

Table Name : StudentField Name Data Type Field Size ConstraintsRoll No Number 8 Primary KeyName Text 20 Not NullAddress Text 50

Table Name : EnrollmentField Name Data Type Field Size ConstraintsRoll No Number 8 Foreign Key,

Primary KeyCourse Text 20 Primary KeyGrade Text 1 ‘A’,’B’,’C’,’D’,’E’

Perform the following operations using SQL Commands

(i) List all the Students enrolled for ‘BBA’ and have grade ‘A’(ii) Find the number of students enrolled in each course.

Ans:-create table student2(rollno number(8) ,name varchar2(20) NOT NULL,address varchar2(50));

Output:-

1

Page 2: Dbms Practical

create table enrollment(rollnumber number(8) ,course varchar2(20),grade varchar2(1) CHECK(grade IN('A','B','C','D','E')));

Output:-

alter table student2 add constraint pk1_primarykey PRIMARY KEY(rollno);

Output:-

2

Page 3: Dbms Practical

alter table enrollment add constraint pk2_primarykey PRIMARY KEY(rollnumber,course);

Output:-

alter table enrollment add constraint fk1_rollnumber FOREIGN KEY(rollnumber) REFERENCES student2(rollno);

Output:-

3

Page 4: Dbms Practical

select * from student2,enrollment where course='bba' and grade='A' and rollno=rollnumber;

Output:-

select count(course) from enrollment GROUP by course;

4

Page 5: Dbms Practical

Q4. Consider EMP table and perform the following using SQL Commands

(i) Add a new column called total sal to the table (ii) Update the total sal column with sal + comm.(iii) Find the employees having salary greater than average salary of the employees

working in dept 10(iv) List employee name and yearly salary and arrange the output on the basis of

yearly salary in descending order.(v) Retrieve the names of departments in ascending order and their employees in

descending order.

Ans:-

create table emp(empno number(8),dept varchar2(20),name varchar2(20),salary number(20),comm number(8));

select * from emp;

5

Page 6: Dbms Practical

alter table emp add totalsal number(20);

update empset totalsal=salary+comm;

6

Page 7: Dbms Practical

select name,salary from emp where salary >(select AVG(salary) from emp);

select name,salary from emp order by salary desc;

7

Page 8: Dbms Practical

select name,dept from emp order by dept asc,name desc;

8

Page 9: Dbms Practical

9