You are on page 1of 16

INSTITUTE OF MANAGEMENT AND TECH.

PRACTICAL FILE
ON RDBMS(RELATIONAL DATABASE MANAGEMENT
SYSTEM)
BATCH(2019-22)
PARTIAL FULFILMENT OF THE AWARD OF DEGREE
OF
BACHELOR OF BUSINESS ADMINISTRATION AND
COMPUTER AIDED MANAGEMENT

SUBMITTED TO: SUBMITTED BY:


Mrs.Jyoti thakur Name:Praveen
Ragistration no:191150111
Rollno:
S.NO DESCRIPTION PAGE NO

WHAT IS RDBMS? DISCUSS THE VARIOUS DATA 1-4


1 MODELS.

DRAW ER DIAGRAM AND COVERT ENTITIES AND 5-6


2 RELATIONSHIP TO RELATION FOR THE GIVEN
SCINARIO:-
TWO ASSIGNMENT SHAAL BE CARRIED OUT THAT
IS CONSIDERED TWO DIFFERENT SCINARIO FOR
EXAMPLE,
COLLEGE.

PERFORM THE FOLLOWING:- 7-9


3 1) CREATE A DATABASE.
2) DOING ALL DATABSE.
3) DOING ALL TABLES IN A DATABASE.
4) CREATE A TABLE(WITH AND WITH CONSTRAINT)
5) INSERT/UPDATE/DELETE A RECORD IN A TABLE.
6) COMMIT AND ROLL BACK

PERFORM THE FOLLOWING:- 10


4 1) ALTERING A TABLE.
2) DROPPING A TABLE.
3) TRANKCATING A TABLE.
4) RENAMING THE TABLE.

FOR A GIVEN SET OF RELATION TABLE PERFORM 11-12


5 FOLLOWING:-
1) CREATING A VIEW.
2) DROPPING A VIEW.
3) SELECTING FROM A VIEW.

GIVEN THE TABLE 13


6 EMPLOYEE(M.NO,NAME,SALARY,DESTINATION,DEPARTMEN
T ID) WRIGHT a query to select a five highest paid employees
from the table.
PRACTICAL 1
RDBMS (relational database
management system)
A relational database management system (RDBMS) is a collection of programs and
capabilities that enable IT teams and others to create, update, administer and
otherwise interact with a relational database. RDBMS es store data in the form of
tables, with most commercial relational database management systems using
Structured Query Language (SQL) to access the database. However, since SQL was
invented after the initial development of the relational model, it is not necessary for
RDBMS use.

The RDBMS is the most popular database system among organizations across the
world. It provides a dependable method of storing and retrieving large amounts of
data while offering a combination of system performance and ease of
implementation.

MODELS
Data Models
Data Model is the modeling of the data description, data semantics, and consistency
constraints of the data. It provides the conceptual tools for describing the design of a
database at each level of data abstraction. Therefore, there are following four data
models used for understanding the structure of the database:

1
1) Relational Data Model: This type of model designs the data in the form of rows
and columns within a table. Thus, a relational model uses tables for representing
data and in-between relationships. Tables are also called relations. This model was
initially described by Edgar F. Codd, in 1969. The relational data model is the widely
used model which is primarily used by commercial data processing applications.

2) Entity-Relationship Data Model: An ER model is the logical representation of data


as objects and relationships among them. These objects are known as entities, and
relationship is an association among these entities. This model was designed by
Peter Chen and published in 1976 papers. It was widely used in database designing.
A set of attributes describe the entities. For example, student_name, student_id
describes the 'student' entity. A set of the same type of entities is known as an
'Entity set', and the set of the same type of relationships is known as 'relationship
set'.

3) Object-based Data Model: An extension of the ER model with notions of


functions, encapsulation, and object identity, as well. This model supports a rich type
system that includes structured and collection types. Thus, in 1980s, various
database systems following the object-oriented approach were developed. Here, the
objects are nothing but the data carrying its properties.

4) Semistructured Data Model: This type of data model is different


from the other three data models (explained above). The
semistructured data model allows the data specifications at places
where the individual data items of the same type may have different
attributes sets. The Extensible Markup Language, also known as XML,
is widely used for representing the semistructured data. Although XML
was initially designed for including the markup information to the

2
text document, it gains importance because of its application in the
exchange of data.

Data model Schema and Instance


 The data which is stored in the database at a particular moment of time is called an instance
of the database.
 The overall design of a database is called schema.
 A database schema is the skeleton structure of the database. It represents the logical view of
the entire database.
 A schema contains schema objects like table, foreign key, primary key, views, columns, data
types, stored procedure, etc.
 A database schema can be represented by using the visual diagram. That diagram shows the
database objects and relationship with each other.
 A database schema is designed by the database designers to help programmers whose
software will interact with the database. The process of database creation is called data
modeling.

A schema diagram can display only some aspects of a schema like the name of
record type, data type, and constraints. Other aspects can't be specified through the
schema diagram. For example, the given figure neither show the data type of each
data item nor the relationship among various files.

In the database, actual data changes quite frequently. For example, in the given
figure, the database changes whenever we add a new grade or add a student. The
data at a particular moment of time is called the instance of the database.

3
4
PRACTICAL 2

ER DIAGRAM
 suppose we design a COLLEGE database. In this database, the student will

be an entity with attributes like address, name, id, age, etc. The address can be
another entity with attributes like city, street name, pin code, etc and there will
be a relationship between them. And in the bank
employees,id,frame,address,contact will be

College Database: E-R Diagram

5
6
PRACTICAL 3
Consider the Company database with following tables

Perform the following:


1.
Create company database
2.
Viewing all databases
3.
Viewing all Tables in a Database,
4.
Creating Tables (With and Without Constraints)
5.
Inserting/Updating/Deleting Records in a Table
6.
Saving (Commit) and Undoing (rollback)

SOLUTION:
1.
Creating a Database
CREATE DATABASE Company;
2.
Viewing all databases
SHOW DATABASES;
3.
Viewing all Tables in a Database,
SHOW tables;
4.
Creating Tables (With and Without Constraints)
CREATE TABLE DEPARTMENT
(DNO VARCHAR2 (20) PRIMARY KEY,
DNAME VARCHAR2 (20),
MGRSTARTDATE DATE);
Dr. Bhagirathi Halalli, Assistant Prof. GFGC-Raibag

7
Page 13
CREATE TABLE EMPLOYEE
(SSN VARCHAR2 (20) PRIMARY KEY,
FNAME VARCHAR2 (20),
LNAME VARCHAR2 (20),
ADDRESS VARCHAR2 (20),
SEX CHAR (1),
SALARY INTEGER,
SUPERSSN REFERENCES EMPLOYEE (SSN),
DNO REFERENCES DEPARTMENT (DNO));
NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter
department
table to add foreign constraint MGRSSN using sql command
ALTER TABLE DEPARTMENT
ADD MGRSSN REFERENCES EMPLOYEE (SSN);

5. Inserting/Updating/Deleting Records in a Table,


INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSECE01‘,‘JOHN‘,‘SCOTT‘,‘BANGALORE‘,‘M‘, 450000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE01‘,‘JAMES‘,‘SMITH‘,‘BANGALORE‘,‘M‘, 500000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE02‘,‘HEARN‘,‘BAKER‘,‘BANGALORE‘,‘M‘, 700000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE03‘,‘EDWARD‘,‘SCOTT‘,‘MYSORE‘,‘M‘, 500000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE04‘,‘PAVAN‘,‘HEGDE‘,‘MANGALORE‘,‘M‘, 650000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE05‘,‘GIRISH‘,‘MALYA‘,‘MYSORE‘,‘M‘, 450000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSCSE06‘,‘NEHA‘,‘SN‘,‘BANGALORE‘,‘F‘, 800000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSACC01‘,‘AHANA‘,‘K‘,‘MANGALORE‘,‘F‘, 350000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSACC02‘,‘SANTHOSH‘,‘KUMAR‘,‘MANGALORE‘,‘M‘, 300000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSISE01‘,‘VEENA‘,‘M‘,‘MYSORE‘,‘M‘, 600000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‗RNSIT01‘,‘NAGESH‘,‘HR‘,‘BANGALORE‘,‘M‘, 500000);
INSERT INTO DEPARTMENT VALUES (‗1‘,‘ACCOUNTS‘,‘01-JAN-
01‘,‘RNSACC02‘);
INSERT INTO DEPARTMENT VALUES (‗2‘,‘IT‘,‘01-AUG-16‘,‘RNSIT01‘);
Dr. Bhagirathi Halalli, Assistant Prof. GFGC-Raibag
Page 14
INSERT INTO DEPARTMENT VALUES (‗3‘,‘ECE‘,‘01-JUN-08‘,‘RNSECE01‘);
INSERT INTO DEPARTMENT VALUES (‗4‘,‘ISE‘,‘01-AUG-15‘,‘RNSISE01‘);
INSERT INTO DEPARTMENT VALUES (‗5‘,‘CSE‘,‘01-JUN-02‘,‘RNSCSE05‘);
Update
UPDATE EMPLOYEE SET DNO=‘5‘, SUPERSSN=‘RNSCSE06‘ WHERE
SSN=‘RNSCSE05‘;

8
Delete entries of employee table where DNO =1;
DELETE FROM EMPLOYEE WHERE DNO=1;
6.
COMMIT and ROLLBACK
Before concluding this section on Data Manipulation Language commands there are
two
further commands, which are very useful. Changes made to the database by INSERT,
UPDATE and DELETE commands are temporary until explicitly committed. This is
performed by the command:
COMMIT;
On execution of this command all changes to the database made by you are made
permanent and cannot be undone.

A COMMIT is automatically executed when you exit normally from SQL*Plus.
However, it does no harm to occasionally issue a COMMIT command.

A COMMIT does not apply to any SELECT commands as there is nothing to
commit.

A COMMIT does not apply to any DDL commands (eg CREATE TABLE,
CREATE INDEX, etc). These are automatically committed and cannot be rolled
back.

If you wished to rollback (ie undo) any changes made to the database since the
last commit, you can issue the command:
ROLLBACK;
A group of related SQL commands that all have to complete successfully or otherwise
be
rolled back, is called a transaction. Part of your research for Outcome 3 includes
investigating transaction processing and the implications of rollback and commit.

9
PRACTICAL 4

Altering a table
SQL Server / MS Access: ALTER TABLE table_name. ALTER COLUMN
column_name datatype;

Dropping a table
All constraints and views that reference the column are dropped automatically, along
with the column.
SQL> ALTER TABLE DEPARTMENT DROP column LOC CASCADE
CONSTRAINTS;
Table altered.
SQL> desc dept
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NOT NULL NUMBER(38)
DNAME VARCHAR2(10)
PINCODE NOT NULL NUMBER(6)

Trankcating a table
{ database_name.schema_name.table_name | schema_name.table_name |
table_name }
[ WITH ( PARTITIONS ( { <partition_number_expression> | <range> }
[ , ...n ] ) ) ]
[ ; ]
<range> ::= <partition_number_expression> TO
<partition_number_expression>

Renaming the table


SQL> ALTER TABLE DEPT RENAME TO DEPARTMENT;
Table altered.

10
PRACTICAL 5
For a given EMPLOYEE tables

Perform the Following


1.
Creating Views (With and Without Check Option),
2.
Selecting from a View
3.
Dropping Views,
SOLUTION:
SQL> CREATE TABLE EMPLOYEE (
SSN VARCHAR2 (20) PRIMARY KEY,
FNAME VARCHAR2 (20),
LNAME VARCHAR2 (20),
ADDRESS VARCHAR2 (20),
SEX CHAR (1),
SALARY INTEGER,
SUPERSSN REFERENCES EMPLOYEE (SSN),
DNO REFERENCES DEPARTMENT (DNO));
SQL> DESC EMPLOYEE;
Name Null?
Type
----------------------------------------- -------- ----------------------------
SSN NOT NULL
VARCHAR2(20)
FNAME
VARCHAR2(20)
LNAME
VARCHAR2(20)
ADDRESS
VARCHAR2(20)
SEX
CHAR(1)
SALARY
NUMBER(38)
SUPERSSN
VARCHAR2(20)
DNO

11
NUMBER(38)
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSECE01‘,‘JOHN‘,‘SCOTT‘,‘BANGALORE‘,‘M‘, 450000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE01‘,‘JAMES‘,‘SMITH‘,‘BANGALORE
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE02‘,‘HEARN‘,‘BAKER‘,‘BANGALORE‘,‘M‘, 700000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE03‘,‘EDWARD‘,‘SCOTT‘,‘MYSORE‘,‘M‘, 500000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE04‘,‘PAVAN‘,‘HEGDE‘,‘MANGALORE‘,‘M‘, 650000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE05‘,‘GIRISH‘,‘MALYA‘,‘MYSORE‘,‘M‘, 450000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSCSE06‘,‘NEHA‘,‘SN‘,‘BANGALORE‘,‘F‘, 800000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSACC01‘,‘AHANA‘,‘K‘,‘MANGALORE‘,‘F‘, 350000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSACC02‘,‘SANTHOSH‘,‘KUMAR‘,‘MANGALORE‘,‘M‘, 300000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSISE01‘,‘VEENA‘,‘M‘,‘MYSORE‘,‘M‘, 600000);
INSERT INTO EMPLOYEE (SSN, FNAME, LNAME, ADDRESS, SEX, SALARY)
VALUES (‘RNSIT01‘,‘NAGESH‘,‘HR‘,‘BANGALORE‘,‘M‘, 500000);
Creating View
The query that defines the sales_staffview references only rows in department 5.
Furthermore, the CHECK OPTION creates the view with the constraint (named
sales_staff_cnst) that INSERT and UPDATE statements issued against the view
cannot
result in rows that the view cannot select.
1. Creating Views (With and Without Check Option)
SQL> CREATE VIEW sales_staff AS
2 SELECT fname, ssn, dno
3 FROM employee
4 WHERE dno =5
5 WITH CHECK OPTION CONSTRAINT sales_staff_cnst;
View created.
2. Selecting from a View
SQL> select * from sales_staff;
3. Drop View
SQL>DROP VIEW sales_staff;

12
PRACTICAL 6
Given the table EMPLOYEE (EmpNo, Name, Salary, Designation, DeptID) write a
QUERY to
select the five highest paid employees from the table.
EMPLOYEE (EmpNo, Name, Salary, Designation, DeptID)
SOLUTION:
CREATE TABLE EMPLOYEE
(EMPNO INTEGER PRIMARY KEY,
NAME VARCHAR(20),
SALARY NUMBER(7,2),
DESIGNATION VARCHAR(10),
DEPTID INTEGER);

13

You might also like