0% found this document useful (0 votes)
23 views

DBMS Lab

Uploaded by

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

DBMS Lab

Uploaded by

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

List of Experiments:

Week-1: CREATION OF
TABLES
1. Create a table called
Employee with the
followingstructure.
Name Type
Empno Number
Ename Varchar2(20)
Job Varchar2(20)
Mgr Number
Sal Number
a. Add a column
commission with domain
to the Employeetable.
b. Insert any five records
into the table.
c. Update the column
details of job
d. Rename the column of
Employ table using alter
command.
e. Delete the employee
whose empno is19.
List of Experiments:

Week-1: CREATION OF TABLES

1. Create a table called Employee with the following structure.

Name Type

Empno Number

Ename Varchar2(20)

Job Varchar2(20)

Mgr Number

Sal Number

a. Add a column commission with domain to the Employeetable.

b. Insert any five records into the table.

c. Update the column details of job

d. Rename the column of Employ table using alter command.

e. Delete the employee whose empno is19.

SOLUTION:
SQL> create table
employee (empno
number,ename
varchar2(10), job
varchar2(10),mgr
number,sal number);
Table created.
SQL> desc employee;
Name
Null?
Type
EMPNO
NUMBER
ENAME
VARCHAR2(10)
JOB
VARCHAR2(10)
MGR
NUMBER
SAL
NUMBER
SQL> create table employee (empno number,ename varchar2(10), job varchar2(10),mgr
number,sal number);
Table created.
SQL> desc employee;

a. Add a column
commission with domain
to the Employee table.
SQL> alter table employee
add(commission number);
Table altered.
SQL> desc employee;
a. Add a column commission with domain to the Employee table.

SQL> alter table employee add(commission number);


Table altered.
SQL> desc employee;
Insert any five records
into the table.
SQL> insert into employee
values(&empno,'&ename','
&job',&mgr,&sal,'&commis
sion');
b. Insert any five records into the table.

SQL> insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission');

EMPNO ENAME JOB MGR


SAL COMMISSION
101
abhi
manager
1234
10000
70
102
rohith
analyst
2345
9000
65
103
david
analyst
3456
9000
65
104
rahul
clerk
4567
7000
55
105
pramod
salesman
5678
5000
EMPNO ENAME JOB MGR
SAL COMMISSION
101
abhi
manager
1234
10000
70
102
rohith
analyst
2345
9000
65
103
david
analyst
3456
9000
65
104
rahul
clerk
4567
7000
55
105
pramod
salesman
5678
5000

c. Update the column


details of job
SQL> update employee
set job='trainee' where
empno=103; 1
row updated.
c. Update the column details of job

SQL> update employee set job='trainee' where empno=103;


1
row updated.
SQL> select * from employee

d. Rename the column


of Employ table using
alter command.
SQL> alter table employee
rename column mgr to
manager_no;
Table altered.
d. Rename the column of Employ table using alter command.

SQL> alter table employee rename column mgr to manager_no;

Table altered.

SQL> desc employee;

Delete the employee whose Empno is 105.

SQL> delete employee where empno=105;


1
row deleted.

WEEK -2
QUERIES USING DDL
AND DML
1.
a. Create a user and grant
all permissions to the user.
b. Insert the any three
records in the employee
table and use rollback.
Check theresult.
c. Add primary key
constraint and not null
constraint to the employee
table.
d. Insert null values to the
employee table and verify
the result.
WEEK -2
QUERIES USING DDL AND DML

1.

a. Create a user and grant all permissions to the user.


b. Insert the any three records in the employee table and use rollback. Check theresult.
c. Add primary key constraint and not null constraint to the employee table.
d. Insert null values to the employee table and verify the result.

SOLUTION:
a)
create a user and grant
all permissions to the
user.
CONNECT <USER-
NAME>/<PASSWORD>@<
DATABASE NAME>;
--Create user query
CREATE USER <USER
NAME> IDENTIFIED BY
<PASSWORD>;
--Provide roles
GRANT
CONNECT,RESOURCE,DBA
TO <USER NAME>;
--Assigning privileges
GRANT CREATE SESSION
GRANT ANY PRIVILEGE TO
<USER NAME>; GRANT
UNLIMITED
TABLESPACE TO <USER
NAME>;
--Provide access to tables.
SOLUTION:

a)

create a user and grant all permissions to the user.

CONNECT <USER-NAME>/<PASSWORD>@<DATABASE NAME>;

--Create user query

CREATE USER <USER NAME> IDENTIFIED BY <PASSWORD>;

--Provide roles

GRANT CONNECT,RESOURCE,DBA TO <USER NAME>;

--Assigning privileges

GRANT CREATE SESSION GRANT ANY PRIVILEGE TO <USER NAME>; GRANT UNLIMITED
TABLESPACE TO <USER NAME>;

--Provide access to tables.


GRANT SELECT, UPDATE, INSERT, DELETE ON <TABLE NAME> TO <USER NAME>;

b)

Insert the any three records in the employee table and use rollback. Check the result

SQL> rollback;
Rollback complete

c)

Add primary key constraint and not null constraint to the employee table.
SQL> alter table employee modify(empno number primary key, ename varchar2(10) not null); Table
altered.
SQL> desc employee;
d)

Insert null values to the employee table and verify theresult.


SQL> desc employee;

Queries using aggregate functions(COUNT,AVG,MIN,MAX,SUM),Group by,Orderby.


Employee(E_id, E_name, Age, Salary)
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2. Count number of employee names from employeetable
3. Find the Maximum age from employee table.
4. Find the Minimum age from employeetable.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.

You might also like