0% found this document useful (0 votes)
14 views19 pages

final dbms

dbms

Uploaded by

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

final dbms

dbms

Uploaded by

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

EXPERIMENT 1

AIM: Implement Data Definition language statements.


1. CREATE TABLE

Source code:

CREATE TABLE Emp1


(
EID int,
E Name varchar(20),
E dept varchar(10),
EDOB Date,
Salary int);

Output:

2. ALTER TABLE
Source code:

CREATE TABLE Emp1(EID int,EName varchar(20),Edept varchar(10),EDOB


Date,Salary int);
ALTER TABLE Emp1 ADD Address varchar(10);
ALTER TABLE Emp1 MODIFY EID varchar(10);
ALTER TABLE Emp1 DROP column Edept ;
ALTER TABLE Emp1 RENAME COLUMN EID TO Roll_no;
desc Emp1

Output:

Table altered.
TABLE Emp1
Colum
n Null? Type
ROLL_NO - VARCHAR2(10)
ENAME - VARCHAR2(20)
EDOB - DATE
SALARY - NUMBER
ADDRESS - VARCHAR2(10)
Download CSV
5 rows selected.
3. DROP TABLE
Source code:
DROP TABLE Emp1;
desc Emp1

Output:
Table dropped. ORA-20001: object EMP1 does not exist

4. RENAME TABLE

Source code:
RENAME Emp1 TO Employee;
desc Employee

Output:

TABLE EMPLOYEE
Colum
n Null? Type
ROLL_NO - VARCHAR2(10)
ENAME - VARCHAR2(20)
EDOB - DATE
SALARY - NUMBER
ADDRES
- VARCHAR2(10)
S

5. TRUNCATE TABLE

Source code:

CREATE TABLE Emp1


(EID int,
EName varchar(20),
Edept varchar(10),
EDOB Date,Salary int);
TRUNCATE TABLE Emp1;
desc Emp1

Output:
The data will be deleted but the structure will remain in the memory for further
operations. Table truncated. TABLE EMP1
EXPERIMENT 2
AIM: Implement Data Manipulation language statements (DML).
1. INSERT

Source Code: Output:

2. SELECT

3. UPDATE
Output:

4. DELETE
EXPERIMENT 3
AIM : Implement select command with different classes.

1. WHERE

2. GROUP BY

3. HAVING

Output:

4. ORDER BY

5. SELECT
EXPERIMENT 4

AIM : Implement various types of integrity constraints on database.

1. NOT NULL AND PRIMARY KEY


CREATE TABLE Student(SID int PRIMARY KEY,SName varchar(30) NOT NULL,Section int NOT
NULL);
INSERT INTO Student values(1,'Tanya',2);
INSERT INTO Student values(2,'Shubham',4);
INSERT INTO Student values(3,'Archit',1);
INSERT INTO Student values(4,'Vishal',3);

2. UNIQUE
Source code: Output:

3. CHECK
4. DEFAULT
EXPERIMENT 5
AIM: Implement single row functions and group functions.

1. SUM

2. AVERAGE

3. COUNT

4. MIN AND MAX


EXPERIMENT 6
AIM-Study of various type of SET OPERATORS

UNION
EXPERIMENT 7
AIM-Study and implement the concept of sub queries
UNION CLAUSE

INTERSECTION CLAUSE

MINUS CLAUSE
EXPERIMENT 8
AIM-Study and implement the concept of data control
language(DCL),Transaction control language (TCL).

COMMIT
EXPERIMENT 9
AIM-Study of Simple and Complex View

CREATE VIEW

OUTPUT

DROP VIEW

The drop view commands deletes a view.

The above sql command drops the “age above 25” view.
EXPERIMENT 10:-

Aim:- Write a PL/SQL block to satisfy some conditions by accepting

input from the user.

Source Code:- SQL> DECLARE

<VARIABLE DECLARATION>;
BEGIN

<EXECUTABLE STATEMENT >;

END;

PL/SQL CODING FOR ADDITION OF TWO NUMBERS

SQL>Set serveroutput on
SQL> declare
a
number;
b
number; c
number;
begin
a:=&a;
b:=&b;
c:=a+b;
dbms_output.put_line(‘sum of’||a||’and’||
b||’is’||c); end;
/

INPUT: Enter value for a: 23 old


6: a:=&a;

new 6: a:=23; Enter


value for b: 12 old 7:
b:=&b;

new 7: b:=12;
OUTPUT:

sum of 23 and 12 is 35

PL/SQL procedure successfully completed


EXPERIMENT 11:-
Aim:- Write a PL/SQL block for greatest of three numbers using IF AND ELSEIF

Source Code:- SQL>Set serveroutput on


SQL> declare
a
number; b
number; c
number; d
number;
begin
a:=&a;
b:=&b;
c:=&b; if(a>b)and(a>c)
then
dbms_output.put_line('A is
maximum'); elsif(b>a)and(b>c)then

dbms_output.put_line('B is maximum');
else

dbms_output.put_line('C is maximum');
end if;
end;

INPUT:

Enter value for a: 21


old 7: a:=&a;
new 7: a:=21;
Enter value for b: 12
old 8: b:=&b;
new 8: b:=12;
Enter value for b: 45
old 9: c:=&b;
new 9: c:=45;

Output:-

C is maximum

PL/SQL procedure successfully completed.

EXPERIMENT 12
Aim:- Write a PL/SQL block for summation of odd numbers using for
LOOP

Source Code:-
DECLARE
-- declare variable num
num NUMBER(3) := 1;
sum1 NUMBER(4) := 0;
BEGIN
WHILE num <= 5 LOOP

-- display odd number


dbms_output.Put_line(num;

-- the sum of all odd


numbers sum1:= sum1 +
num;

--next odd number


num := num + 2;

-- end loop
END LOOP;

dbms_output.Put_line('Sum of all odd numbers is '||


sum1); END;
Output:

You might also like