Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
299 views

DBMS - Assignment/Answer/course - Stu - Regis - Assign

The document describes the creation of tables for courses, students, and student registrations in a database. It inserts data into the tables and provides 29 SQL queries to retrieve, update, and analyze the data. Some examples are adding a column to the student table, updating the student ages, retrieving courses by duration or fees, joining tables to find total fees by student, and aggregating registrations by course.

Uploaded by

vishwas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
299 views

DBMS - Assignment/Answer/course - Stu - Regis - Assign

The document describes the creation of tables for courses, students, and student registrations in a database. It inserts data into the tables and provides 29 SQL queries to retrieve, update, and analyze the data. Some examples are adding a column to the student table, updating the student ages, retrieving courses by duration or fees, joining tables to find total fees by student, and aggregating registrations by course.

Uploaded by

vishwas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

COURSE

create table COURSE (CourseID number(4) primary key, CourseName varchar2(20), Duration number(1),
Fees number(7,2));

Inserting Values into Course:

insert into course values('1001','Java','4','5000');

insert into course values('1002','C++','2','4000');

insert into course values('1003','Linux and C','3','4000');

insert into course values('1004','Oracle','2','3000');

insert into course values('1005','C Sharp','6','10000');

STUDENT

create table student (StudId number(4) Primary key, FirstName varchar2(10), LastName varchar2(10),
Street Varchar2(15), City Varchar2(15), DOB date);

Inserting Values into student:

insert into student values('3001','Dileep','Kumar','Jai Nagar','Bangalore','10-Mar-1989');

insert into student values('3002','Anand','Kumar','Indiranagar','Bangalore','19-Jan-1988');

insert into student values('3003','Bala','Krishnan','Annanagar','Channai','03-Jan-1990');

insert into student values('3004','Gowri', 'Shankar', 'Gandhipuram','Coimbatore','22-Dec-1987');

insert into student values('3005','Priya', 'Menon', 'JPNagar','Cochin','12-Feb-1990');

insert into student values('3006','Prem', 'Kumar', 'Ramnagar','Coimbatore','17-May-1987');

insert into student values('3007','Rahul', 'Dravid', 'KKNagar','Chennai','08-Oct-1987');

insert into student values('3008','John', 'Dravid', 'Mylapore','Chennai','15-Sep-1987');

insert into student values('3009','Abdul', 'Rahman', 'HAL','Bangalore','19-Jan-1988');

REGISTRATION

create table REGISTRATION (CourseID number(4) references course(CourseID), StudId number(4)


references student(StudId), DOB date);

Inserting Values into Registration:

insert into REGISTRATION values('1001','3004','10-Mar-2011');


insert into REGISTRATION values('1001','3005','10-Mar-2011');

insert into REGISTRATION values('1002','3002','18-Apr-2011');

insert into REGISTRATION values('1002','3003','18-Apr-2011');

insert into REGISTRATION values('1002','3008','18-Apr-2011');

insert into REGISTRATION values('1003','3001','06-Jun-2011');

insert into REGISTRATION values('1003','3004','06-Jun-2011');

insert into REGISTRATION values('1003','3006','06-Jun-2011');

insert into REGISTRATION values('1004','3005','10-Mar-2011');

insert into REGISTRATION values('1004','3007','10-Mar-2011');

insert into REGISTRATION values('1004','3008','10-Mar-2011');

insert into REGISTRATION values('1005','3004','25-May-2011');

insert into REGISTRATION values('1005','3005','25-May-2011');

1. alter table student add age number(2);

2. alter table COURSE add constraint non_zero check (fees>0);

3. update student set age = round((SYSDATE-DOB)/356);

4. select coursename, fees-500 "new fees" from course where duration <=3;

5. delete from student where lastname='David' and city='Chennai'; (note this query will lead to error
since this table is being referred by another table called registration).

6. select firstname, lastname, firstname||' '||lastname as fullname from student;

7. select * from course where coursename='C++';

8. Select * from course where fees>4000;

9. select * from course where duration between 2 and 4;

10. select * from student where EXTRACT(Month FROM dob) between 04 and 09;

(Or) select * from student where to_char(dob, 'mm') between 04 and 09;

11. Select * from course where Duration=2 and fees>3000;

12. Select * from student where StudId=3002 OR StudId=3004 OR StudId=3005; (or)


Select * from student where StudId IN(3002,3004,3005);

13. Select * from student where lastname='Kumar' or lastname='kumar';

14. select * from student where firstname LIKE 'A%';

15. select * from student where city='Bangalore' AND lastname='Kumar';

16. select * from student where Street LIKE '%nagar';

17. select * from student where firstname ='Dileep' or firstname='Abdul';

18. select * from student where DOB =(select min(DOB) from student);

19. select * from student where StudId != 3004 and StudId != 3006; (Or)

select * from student where StudId NOT IN(3004,3006);

20. select MAX(fees) as max_fees, MIN(fees) as min_fees,AVG(fees) as avg_fees from course;

21. Select count(*) as count from student;

22. select DISTINCT city from student;

23. select * from student order by DOB DESC;

24. select count(StudId) from REGISTRATION where DOB='10-Mar-2011';

25. select UPPER(firstname), LOWER(lastname),Initcap(city) from student;

26. select courseid, count(studid) from registration group by courseid;

27. select studid from registration group by studid having count(courseid)>1;

28. select * from student where length(firstname)=4;

SUBQUERIES AND JOINS:

1. select * from course where fees <(select max(fees) from course);

2. select * from student where dob < (select dob from student where firstname='Bala' and
lastname='Krishnan');

3. select sum(c.fees) sum from student s, course c, registration r where s.studid=r.studid and
r.courseid=c.courseid and s.city='Bangalore';
4. select s.firstname, c.coursename from student s, course c, registration r where s.studid=r.studid and
r.courseid=c.courseid order by coursename;

5. select c.* from course c, course e where e.fees=c.fees and e.courseid != c.courseid;

6. select r.studid,add_months(r.doj,c.duration) as DOC from registration r, course c;

7. select max(fees) from course where fees <(select max(fees) from course);

8. select r.studid, sum(c.fees) as total_fees from course c, registration r where r.courseid = c.courseid
group by (r.studid) order by r.studid;

9. select r.courseid, c.coursename, sum(c.fees) total_fees from course c, registration r where c.courseid=
r.courseid group by r.courseid, c.coursename order by r.courseid;

You might also like