Dbms Manual II It

31
VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE DATABASE MANAGEMENT SYSTEMS Branch&Year:II IT,I Sem SI.NO NAME OF THE EXPERIMENT PAGE NO. 1 2 3 4 5 6 7 8 9 10 CREATING TABLES FOR VARIOUS RELATIONS IN SQL IMPLEMENTING THE QUERIES IN SQL FOR A.INSERTION B.RETRIVAL C.UPDATION D.DELETION CREATING VIEWS WRITING ASSERTIONS WRITING TRIGGERS PL/SQL PROGRAM FOR FINDING FACTORIAL OF A GIVEN NUMBER PL/SQL PROGRAM FOR FINDING FIBANACCI SERIES OF A GIVEN NUMBER PL/SQL PROGRAM TO FIND AREA OF CIRCLE FOR THE GIVEN RANGE OF RADIUS. PL/SQL PROGRAM FOR WITHDRAWING MONEY FROM GIVEN ACCOUNT NUMBER PL/SQL PROGRAM FOR DEPOSITING MONEY TO THE GIVEN ACCOUNT NUMBER PL/SQL PROGRAM FOR TRANSFERING MONEY FROM ONE ACCOUNT TO ANOTHER ACCOUNT PL/SQL PROGRAM FOR DISPLAYING HIGHEST DATABASE MANAGEMENT SYSTEMS LAB PAGE NO: 1

description

DBMS

Transcript of Dbms Manual II It

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE

DATABASE MANAGEMENT SYSTEMSBranch&Year:II IT,I Sem

SI.NO 1 2

NAME OF THE EXPERIMENT CREATING TABLES FOR VARIOUS RELATIONS IN SQL IMPLEMENTING THE QUERIES IN SQL FOR A.INSERTION B.RETRIVAL C.UPDATION D.DELETION CREATING VIEWS WRITING ASSERTIONS WRITING TRIGGERS PL/SQL PROGRAM FOR FINDING FACTORIAL OF A GIVEN NUMBER PL/SQL PROGRAM FOR FINDING FIBANACCI SERIES OF A GIVEN NUMBER PL/SQL PROGRAM TO FIND AREA OF CIRCLE FOR THE GIVEN RANGE OF RADIUS. PL/SQL PROGRAM FOR WITHDRAWING MONEY FROM GIVEN ACCOUNT NUMBER PL/SQL PROGRAM FOR DEPOSITING MONEY TO THE GIVEN ACCOUNT NUMBER PL/SQL PROGRAM FOR TRANSFERING MONEY FROM ONE ACCOUNT TO ANOTHER ACCOUNT PL/SQL PROGRAM FOR DISPLAYING HIGHEST BALANCE OF FIVE CUSTOMERS PL/SQL PROGRAM FOR FINDING GRADE AND AVERAGE OF THE STUDENT IN STUDENT TABLE PL/SQL PROGRAM TO FIND GIVEN NO IS PRIME OR NOT

PAGE NO.

3 4 5 6

7

8

9

10

11

12

13

14

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

1

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE

1.CREATING TABLES FOR VARIOUS RELATIONS IN SQLSyntax for creating table:Create table table name(column1 datatype,column2 datatype);

1.Create table for the following schema.(with out constraints) Student(sid:int,sname:string,age:int,dob:date); Query. Create table Student(sid int,sname varchar(20),age int,dob date); The above table can be described using Desc command as, Desc Student; It can display the Student table. 2. Create table for the following schema.(with primary key constraint). Student(sid:int,sname:string,age:int,dob:date); Create table Student(sid int constraint pkey primary key, sname varchar(20),age int,dob date); 3. Create table for the following schema.(with primary key constraint and not null). Student(sid:int,sname:string,age:int,dob:date); Create table Student(sid int constraint pkey primary key, sname varchar(20) not null, age int,dob date); 4. Create table table for the following schema.(with check constraint age between 18 to 26); Student(sid:int,sname:string,age:int,dob:date); Create table Student(sid int, sname varchar(20), age int constraint chkey check(age between 18 and 26); 5.Creating a table from another table. Syntax:Create table newtablename as select * from existingtablename; Crate a student2 table using any existing table. Query :Create table student2 as select * from student;

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

2

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE

Create a table including foreign key.6.Creating table library which contains sid ,this sid having reference from student table. Query:create table library(sid int ,sname varchar(20),bid int,constraint fkey foreign key(sid) references student(sid));

7.create a student table which contains some of fields of existing student tanle. Query.Create table student3 as select sid,sname ,age from Student.

This can create a new student3 table with sid ,sname,sage columns of student table.

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

3

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE

2..IMPLEMENTING THE QUERIES IN SQLA.INSERTION SYNTAX FOR INSERTION:1.Insert into tablenme values(column1 value,column2 value.); 2. Insert into tablenme values(valuefor column1,value for column2.); Example: Insert the following details into student table: Sid:101,sname:ravi,sgae:23,dob:11-05-1984. Query:Insert into student values(101,ravi,23,11-may-1984); Or Insert into student values(sid 101,sname ravi,age 23,dob 11-may-1984); It can insert the values into student table. The inserted values can be displayed by using select command as Select * from student;

B. RETRIVALSELECTION BASED ON SIMPLE QUERIES; Create the tables for the following schema. Student(sid:int,sname:string;sage:int); Insert the values into student table. QUERIES: 1.Display the all students details? Select * from students; 2.Dispaly the all students ids and names ? select sid,sname from students; 3.Find the names of all students whose age is less than 23; Select * from students where sage23;

Selection based on LIKE operator: 1.Find the sids of students whose name starts with a? select sid from students where sname like a%; 2. .Find the sids of students whose name ends with a? select sid from students where sname like %a; 3. Find the sids of students whose name contains exactly 4 characters? select sid from students where sname like ____; 4. Find the sids of students whose name starts with aand ends with a? Select sid from students where sname like a%a; 5. Find the sids of students whose name starts with aand ends with a and having 5 characters? Select sid from students where sname like a___a;

SELECTION BASED ON JOINS: Create the tables for the following schemas. Sailors(sid :int,sname:string,rating:int,age:int); Boats(bid:int,bname:string,bcolour:string); Reserves(sid:int,bid:int,day:date); Insert the values into above three tables. Queries: 1.Find the names of sailors who have reserved boat no 103? Select sname from sailors s,reserves r where r.bid=103 and s.sid=r.sid; 2. Find the names of sailors who have reserved red boat? Select sname from sailors s,reserves r where b.colour=red and b.bid=r.bid and r.sid=s.sid; 3.find the names of sailors who have reserved atleast one boat? Select distinct sname from sailors s,reserves r where s.sid=r.sid;

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

5

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE SELECTION BASED ON NESTED QUERIES: 1.Find the names of sailors who have reserved a red boat or green boat? Select sname from sailors s where sid in(select r.sid from reservesr where r.bid in (select bid from boats b where b.colour=red or b.colour=green)); 2. .Find the names of sailors who have reserved a red boat and green boat? Select sname from sailors s where sid in(select r.sid from reservesr where r.bid in (select bid from boats b where b.colour=red and b.colour=green));

SELECTION USING ANY OPERATOR: 1.Find the names of all sailors whose rating is greater than sailor x? Select sanme from sailors s where s.rating > any(select s1.rating from sailors s1 where s1.name=x); SELECTION BASED ON ORDER BY: 1.Display all the sailors in alphabetical order? Select * from sailors order by sname; SELECTION USING IS NULL: 1.Find the names of sailors whose rating is not inserted? Select * from sailors where rating is null; SELECTION BASED ON AGGREGATION FUNCTIONS: Create table for the following databse. Students(sid:integer,sname:string,marks:integer,age:integer); Insert values into Students table. Query: 1.Find the minimum marks of the students table? Select min(marks) from students;

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

6

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE 2. .Find the maximum marks of the students table? Select max(marks) from students; 3.Find the average marks of the students from the students table? Select avg(marks) from students; 4.Find the no.of students from in the student table? Select count(sid) from students;

SELECTION BASED ON GROUP BY Create table customer(cid,cname,loanamount); Insert values into customer table. 1.Find the loanamount taken by each customer? Select cid ,sum(loanamount) from customer group by cid;

SELECTION BASED ON HAVING

Create table customer(cid,cname,loanamount); Insert values into customer table. 1.Find the cids whose loanamount greater than 10000? Select cid,sum(loanamount) from customer group by cid,having sum(loanamount)>10000; SELECTION BASED ON UNION AND INTERSECTION

Create table customer1(cid,cname); Insert values into customer. Create table customer2(cid,cname); Insert values into customer2. 1.Find the cids exist in customer1 and customer2 tables?

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

7

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE

Select cid from customer1 UNION select cid from customer2;

2.Find the cids exist in both customer1 and customer2 tables?

Select cid from customer1 intersect select cid from customer2;

C.UPDATION& ALTER: 1.Add rank attribute to an existing student table ? Alter table student add rank number(10); 2.Add join date attribute to an employee table? Alter table employee add joindate date; 3.Increase the size of name attribute in student table? Alter table student modify sname char(20)); 4.Change the student name whose number is 103; Update student set sname=xxx where sid=103; 5. Change the student marks whose number is 103; Update student set marks=80 where sid=103;

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

8

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE D.DELETE&DROP: 1.Delete student information from student table whose no.is 101? Delete from student where sid=101; 2.Delete student table? Drop table student; 3.Delete employee information from employee table whose eid is 115? Delete from employee where eid=115;

3.CREATING VIEWS.

SYNTAX FOR VIEW:Create view viewname as select * from existingtable;

Procedure:Create a sailors table. After create the following views. Slect details from views. 1.Create a view for sailors table? Craete view sail as select * from sailors; 2.Create view which contains sailor-id,.sailor-name of sailors table whose rating between 3 to 5? Create view sail2 as select sid,sname from sailors where rating between 3 and 5?

DATABASE MANAGEMENT SYSTEMS LAB

PAGE NO:

9

VAAGDEVI INSTITUTE OF TECHNOLOGY AND SCIENCE 3. Create view which contains sailor-id,.sailor-name of sailors and rename sailor-id and sailorname whose age between 20 to 25? Create view sail22(sid1,sname1) as select sid,sname from sailors where age between 20 and 25; 4.Delete a view from databse? Drop view viewname ; 5.Dispaly the details from view? Select * from viewname;

Perform all insertion ,deletion updation operations on base table and

4.WRITING ASSERTIONSAssertions are used to set a conditions in more than one table. Procedure:

Create sailors ,boats and reserves tables. After create assertion and insert values into 3 tables. Create following assertions. 1.Create assertion for sailors and boats tables as the no.of boats+no.of sailors be less than 100; Create assertion ass1 check(((select count(*) from sailors) + (select count(*) from boats ))