0% found this document useful (0 votes)
32 views55 pages

BCS403-Lab Manual

The document is a lab manual for the Database Management Systems course (BCS403) at RV Institute of Technology and Management, outlining the syllabus, experiments, and evaluation criteria. It covers essential topics such as SQL queries, database design, and NoSQL concepts, along with practical exercises and grading policies for Continuous Internal Evaluation (CIE) and Semester End Examination (SEE). The manual also includes detailed instructions on SQL commands and database management techniques.

Uploaded by

Akarsh AK
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)
32 views55 pages

BCS403-Lab Manual

The document is a lab manual for the Database Management Systems course (BCS403) at RV Institute of Technology and Management, outlining the syllabus, experiments, and evaluation criteria. It covers essential topics such as SQL queries, database design, and NoSQL concepts, along with practical exercises and grading policies for Continuous Internal Evaluation (CIE) and Semester End Examination (SEE). The manual also includes detailed instructions on SQL commands and database management techniques.

Uploaded by

Akarsh AK
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/ 55

RV Institute of Technology and Management®

RV Educational Institutions®
RV Institute of Technology and
Management
(Affiliated to VTU, Belagavi)

JP Nagar 8th Phase, Bengaluru - 560076


Department of
Computer Science and Engineering

Lab Manual

Database Management Systems Laboratory (IPCC)

Course Code: BCS403


IV Semester
2022 Scheme
RV Institute of Technology and
Management®

Sl Particulars
No
1 SYLLABUS
2 INTRODUCTION TO DATABASE
3 BASIC QUERIES IN SQL
4 PRACTISE EXERCISES
5 EXPERITMENT 1 – Create user and Grant DB permissions
6 EXPERITMENT 2 – Employee Table and Basic DML operations
7 EXPERITMENT 3 - Employee Table and Aggregate operations
8 EXPERITMENT 4 – Customer Table and Create row level Trigger
9 EXPERITMENT 5 - Create cursor for Employee table
10 EXPERITMENT 6 - PL/SQL code using parameterized Cursor
11 EXPERITMENT 7 - Install an MangoDB and Create CRUD operation
12 VIVA QUESTIONS

DATABASE MANAGEMENT
SYSTEMS(BCS403) 1
RV Institute of Technology and
Management®

DATABASE MANAGEMENT
SYSTEMS(BCS403) 2
RV Institute of Technology and
Management®

DATABASE MANAGEMENT
SYSTEMS(BCS403) 3
RV Institute of Technology and
Management®

Laboratory Outcome

DATABASE MANAGEMENT
SYSTEMS(BCS403) 4
RV Institute of Technology and
Management®

 Define the basics of Databases, Relational model, Relational Algebra and explore the needs and
concepts of SQL queries, Normalization rules, transaction processing and NoSQL concepts.
 Demonstrate and describe database objects, enforce integrity constraints, implement
the transaction processing on a database and NoSQL databases.
 Apply the knowledge of DBMS architecture, Relational algebra, Database design concepts,
transaction processing techniques and NoSQL concepts to design and build simple database
applications.
 Develop applications using relational data model concepts or NoSQL.

The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End
Exam (SEE) is 50%. The minimum passing mark for the CIE is 40% of the maximum
marks (20 marks). A student shall be deemed to have satisfied the academic requirements
and earned the credits allotted to each subject/ course if the student secures not less than
35% (18 Marks out of 50) in the semester-end examination (SEE), and a minimum of
40% (40 marks out of 100) in the sum total of the CIE (Continuous Internal Evaluation)
and SEE (Semester End Examination) taken together

CIE for the theory component of the IPCC (maximum marks 50)

● IPCC means practical portion integrated with the theory of the course.

● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.

● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests
(Two Tests, each of 15

DATABASE MANAGEMENT
SYSTEMS(BCS403) 5
RV Institute of Technology and
Management®

Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment methods
mentioned in

22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second test after
covering 85-90% of

the syllabus.

● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for
the theory

component of IPCC (that is for 25 marks).

● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.

CIE for the practical component of the IPCC

● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks
for the test to be

conducted after the completion of all the laboratory sessions.

● On completion of every experiment/program in the laboratory, the students shall be evaluated


including viva-voce

and marks shall be awarded on the same day.

● The CIE marks awarded in the case of the Practical component shall be based on the
continuous evaluation of the

DATABASE MANAGEMENT
SYSTEMS(BCS403) 6
RV Institute of Technology and
Management®

laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’
write-ups are

added and scaled down to 15 marks.

● The laboratory test (duration 02/03 hours) after completion of all the experiments shall be
conducted for 50 marks

and scaled down to 10 marks.

● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory
component of IPCC

for 25 marks.

● The student has to secure 40% of 25 marks to qualify in the CIE of the practical
component of the IPCC.

SEE for IPCC

Theory SEE will be conducted by University as per the scheduled timetable, with common question papers
for the course

(duration 03 hours)

1. The question paper will have ten questions. Each question is set for 20 marks.

2. There will be 2 questions from each module. Each of the two questions under a module (with a
maximum of 3 subquestions),

should have a mix of topics under that module.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 7
RV Institute of Technology and
Management®

3. The students have to answer 5 full questions, selecting one full question from each module.

4. Marks scoredby the student shall be proportionally scaled down to 50 Marks

The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion will have
a CIE

component only. Questions mentioned in the SEE paper may include questions from the practical
component.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 8
RV Institute of Technology and
Management®

INTRODUCTION TO DATABASE

What is Database?

A database is a separate application that stores a collection of data. Each database has one or
more distinct APIs for creating, accessing, managing, searching, and replicating the data it
holds. now a days we use relational database management systems (RDBMS) to store and
manager huge volume of data.

A Relational DataBase Management System (RDBMS) is a software that:

Enables you to implement a database with tables, columns, and


indexes.Guarantees the Referential Integrity between rows of various
tables.
Interprets an SQL query and combines information from various tables.

RDBMS Terminology:

Database: A database is a collection of tables, with related data.

Table: A table is a matrix with data. A table in a database looks like a simple spreadsheet.

Column: One column (data element) contains data of one and the same kind, for example the column
postcode. or phone numbers

Row: A row (= tuple, entry or record) is a group of related data, for example the data of one
subscription.

Redundancy: Storing data twice, redundantly to make the system faster.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 9
RV Institute of Technology and
Management®

Primary Key: A primary key is unique. A key value can not occur twice in one table. With a key
you can find at most one row.

Foreign Key: A foreign key is the linking pin between two tables.

Compound Key: A compound key (composite key) is a key that consists of multiple columns,
because one column is not sufficiently unique.

Index: An index in a database resembles an index at the back of a book.

Referential Integrity: Referential Integrity makes sure that a foreign key value always points
to an
existing row.
DDL or Data Definition Language actually consists of the SQL commands that can be used to
to create and modify the structure of database objects in a database. These database objects
include views, schemas, tables, indexes, etc.

Some examples:
 CREATE - to create objects in the database
 ALTER - alters the structure of the database
 DROP - delete objects from the database
 DML is Data Manipulation Language statements: which are used to interact with a
database by deleting, inserting, retrieving, or updating data in the database.
 Some examples:
 SELECT - retrieve data from the a database INSERT - insert data into a table
 UPDATE - updates existing data within a table
 DELETE - deletes all records from a table, the space for the records remain
 DCL is Data Control Language statements: which includes commands such as GRANT
and REVOKE which mainly deals with the rights, permissions and other controls of the
database system.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 10
RV Institute of Technology and
Management®

 GRANT-gives access privileges to database.


 REVOKE-withdraw access privileges given by using the GRANT command.
 TCL is Transaction Control Language which deals with a transaction within a database.
Some examples:
 COMMIT - save work done
 SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
 SET TRANSACTION - Change transaction options like what rollback segment to use.

SQL Data Types


Each column in a database table is required to have a name and a data type.
An SQL developer must decide what type of data that will be stored inside each column when
creating a table. The data type is a guideline for SQL to understand what type of data is expected
inside of each column, and it also identifies how SQL will interact with the stored data.
MySQL uses many different data types broken into three categories
 Numeric
 Date and Time
 String Type

CREATE TABLE
Specifies a new base relation by giving it a name, and specifying each of its attributes and their data
types
Syntax of CREATE Command:

CREATE TABLE<table name>


(<AttributeA1><Data TypeD1>
[<Constraints>],
<Attribute A2><Data Type D2> [<Constraints>],

<Attribute An><Data Type Dn> [<Constraints>],

DATABASE MANAGEMENT
SYSTEMS(BCS403) 11
RV Institute of Technology and
Management®

[<integrity-constraint1>, <integrity-constraint k> ] );


Specifying the unique, primary key attributes, secondary keys, and referential integrity constraints

EXAMPLE OF CREATING TABLE

CREATE TABLE
ORDERS (
ORDER_ID INT (6) PRIMARY KEY,
ORDER_DATE DATE
);

ALTER TABLE STATEMENT


Once a table is created in the database, there are many occasions where one may wish to change the structure of
the table. Typical cases include the following:
Add a column
Drop a column
Change a column name
Change the data type for a column
Add and drop various constraints on an existing table.including primary key and foreign

SQL syntax for ALTER TABLE is


ALTER TABLE "table_name" [alter specification]

[alter specification] is dependent on the type of alteration we wish to perform. alter specification is
already mentioned above

ADDING COLUMN IN TABLE

To add a column in a table, use the following syntax:

ALTER TABLE TABLENAME ADD COLUMN_NAME DATETYPE;

DATABASE MANAGEMENT
SYSTEMS(BCS403) 12
RV Institute of Technology and
Management®

Example: ALTER TABLE ORDERS ADD JOB VARCHAR (20);


MODIFYING DATATYPE FOR COLUMN IN TABLE
To modify a column data type in a table, use the following syntax:

ALTER TABLE ORDERS MODIFY COLUMN_NAME VARCHAR (50);

Example: ALTER TABLE ORDERS MODIFY JOB VARCHAR (50);

RENAMING COLUMN IN TABLE

You can rename a column in MySQL using the ALTER TABLE and CHANGE commands together
to change an existing column.

For example,say the column is currently named JOB, but you decide that DESIGNATION is a more
appropriate title. The column is located on the table entitled ORDERS.

Here is an example of how to change it:

ALTER TABLE TABLENAME CHANGE OLDNAME NEWNAME VARCHAR (20);

Example:ALTER TABLE ORDERS CHANGE JOB DESIGNATION VARCHAR (20);

DELETING COLUMN

To delete a column in a table, use the following syntax:

ALTER TABLE TABLENAME DROP COLUMN COLUMN_NAME

Example: ALTER TABLE ORDERS DROP COLUMN DESIGNATION;

RENAMING A TABLE

DATABASE MANAGEMENT
SYSTEMS(BCS403) 13
RV Institute of Technology and
Management®

To rename a table, use the following syntax:

RENAME TABLE OLDTABLENAME TO NEWTABLENAME;

Example: RENAME TABLE ORDERS TO ORDERS_TBL


DROP TABLE
It is very easy to drop an existing MySQL table, but you need to be very careful while deleting any
existing table because the data lost will not be recovered after deleting a table.

The DROP TABLE statement is used to drop an existing table in a database DROP
TABLE TABLENAME;
Example: DROP TABLE ORDER

TRUNCATE TABLE STATEMENT

if we wish to simply get rid of the data but not the table itself? For this, we can use the

TRUNCATE TABLE command.

The syntax for TRUNCATE TABLE is


TRUNCATE "table_name"
So, if we wanted to truncate the table called customer that we created in MYSQL , we simply type,

Example:TRUNCATE customer

CONSTRAINTS:

Common types of constraints include the following:

Primary Key:-
A primary key is used to uniquely identify each row in a table. It can either be part of
the actual record itself, or it can be an artificial field (one that has nothing to do with the

DATABASE MANAGEMENT
SYSTEMS(BCS403) 14
RV Institute of Technology and
Management®

actual record).
A primary key can consist of one or more fields on a table. When multiple fields are
used as a primary key, they are called a composite key.
Primary keys can be specified either when the table is created (using CREATE
TABLE) or by changing the existing table structure (using ALTER TABLE).
Below are examples for specifying a primary key when creating a table:

Example :

CREATE TABLE ORDERS (ORDER_ID INT (6) PRIMARY KEY, ORDER_DATE DATE);
Below are examples for specifying a primary key by altering a table: CREATE TABLE ORDERS
(ORDER_ID INT (6), ORDER_DATE DATE);

Example :ALTER TABLE ORDERS ADD PRIMARY KEY (ORDER_ID);

Note: - Before using the ALTER TABLE command to add a primary key, you'll need to make
sure that the field is defined as 'NOT NULL' -- in other words, NULL cannot be an accepted
value for that field.and column values must be unique

ALTER TABLE TABLENAME DROP PRIMARY KEY CONSTRAINT


To drop a PRIMARY KEY constraint in Table ORDERS, use the following MYSQL:syntax

Example:ALTER TABLE ORDERS DROP PRIMARY KEY

FOREIGN KEY
A foreign key is a field (or fields) that points to the primary key of another table.
The purpose of the foreign key is to ensure referential integrity of the data. In other
words, only values that are supposed to appear in the database are permitted
For example, say we have two tables, a CUSTOMER table that includes all customer

DATABASE MANAGEMENT
SYSTEMS(BCS403) 15
RV Institute of Technology and
Management®

data, and an ORDERS table that includes all customer orders. The constraint here is that
all orders must be associated with a customer that is already in the CUSTOMER table.
In this case, we will place a foreign key on the ORDERS table and have it relate to the
primary key of the CUSTOMER table. This way, we can ensure that all orders in the
ORDERS table are related to a customer in the CUSTOMER table. .In other words, the
ORDERS table cannot contain information on a customer that is not in the CUSTOMER
table.

The structure of these two tables will be as follows: Table CUSTOMER


column name Characteristic
SID Primary Key
Last_Name varchar(50)
First_Name varchar(50)

column name characteristic


Order_ID Primary Key
Order_Date Date
Customer_SID Foreign Key
Amount Decimal(10,2)

CREATE TABLE
CUSTOMER (
SID INT PRIMARY KEY,
Last_Name varchar(50),
First_Name varchar(50)
);

In the below example, the Customer_SID column in the ORDERS table is a foreign
key pointing to the SID column which is primary key in the CUSTOMER table.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 16
RV Institute of Technology and
Management®

Below we show examples of how to specify the foreign key when creating the
ORDERS table: CREATE TABLE ORDERS
(
Order_ID int,
Order_Date
date,
Customer_SID
int, Amount
double,
Primary Key (Order_ID),
Foreign Key (Customer_SID) references CUSTOMER(SID)
);

Below are examples for specifying a foreign key by altering a table.


This assumes that the ORDERS table has been created, and the foreign key has not yet
been put in

ALTER TABLE ORDERS ADD FOREIGN KEY (customer_sid)


REFERENCES CUSTOMER(SID);

We can drop a foreign key by using below syntax

ALTER TABLE ORDERS DROP FOREIGN KEY FOREIGNKEY_CONSTRAINT_NAME;

NOT NULL Constraint:-By default, a column can hold NULL. If you want to allow
or store NULL value in a column, you will want to place a constraint on this column
specifying that NULL is now not an allowable value.

DEFAULT Constraint:- The DEFAULT constraint provides a default value to a


column when the INSERT INTO statement does not provide a specific value.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 17
RV Institute of Technology and
Management®

UNIQUE Constraint:-The UNIQUE constraint ensures that all values in a column are distinct.

CHECK Constraint:-The CHECK constraint ensures that all values in a column satisfy certain
conditions. Once defined, the database will only insert a new row or update an existing row if the
new
value satisfies the CHECK constraint. The CHECK constraint is used to ensure data quality.

BASIC QUERIES IN SQL

SQL (Structured Query Language):


• Structured Query Language is a database computer language designed for managing data in
relational database management systems (RDBMS), and originally based upon Relational
Algebra. Its scope includes data query and update, schema creation and modification, and data
access control.SQL was one of the first languages for Edgar F. Codd's relational model and
became the most widely used language for relational databases.
• IBM developed SQL in mid of 1970’s.
• Oracle incorporated in the year 1979.
• SQL used by IBM/DB2 and DS Database Systems.
• SQL adopted as standard language for RDBS by ASNI in 1989.
• SQL has one basic statement for retrieving information from a database; the SLELECT
statement
• This is not the same as the SELECT operation of the relational algebra Important distinction
• between SQL and the formal relational model;
• SQL allows a table (relation) to have two or more tuples that are identical in all their attribute
values

DATABASE MANAGEMENT
SYSTEMS(BCS403) 18
RV Institute of Technology and
Management®

• Hence, an SQL relation (table) is a multi-set (sometimes called a bag) of tuples;not a set of
tuples
• SQL relations can be constrained to be sets by using the CREATE UNIQUE INDEX
command, or by using the DISTINCT option

DATA TYPES:
1. CHAR (Size): This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of
character is 255 characters.

2. VARCHAR (Size) / VARCHAR2 (Size): This data type is used to store variable length
alphanumeric data. The maximum character can hold is 2000 character.

3. NUMBER (P, S): The NUMBER data type is used to store number (fixed or floating point).
Number of virtually any magnitude may be stored up to 38 digits of precision. Number as large
as 9.99 * 10 124. The precision (p) determines the number of places to the right of the decimal.
If scale is omitted then the default is zero. If precision is omitted, values are stored with their
original precision up to the maximum of 38 digits.

4. DATE: This data type is used to represent date and time. The standard format is DD- MM-YY as
in 17-SEP-2009. To enter dates other than the standard format, use the appropriate functions.
Date time stores date in the 24-Hours format. By default the time

in a date field is 12:00:00 am, if no time portion is specified. The default date for a date field is the
first day the current month.

5. LONG: This data type is used to store variable length character strings containing up to 2GB.
Long data can be used to store arrays of binary data in ASCII format. LONG values cannot be
indexed, and the normal character functions such as SUBSTR cannot be applied.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 19
RV Institute of Technology and
Management®

6. RAW: The RAW data type is used to store binary data, such as digitized picture or image. Data
loaded into columns of these data types are stored without any further conversion. RAW data
type can have a maximum length of 255 bytes. LONG RAW data type can contain up to 2GB.

SQL language is sub-divided into several language elements, including:

 Clauses, which are in some cases optional, constituent components of statements and queries.
 Expressions, which can produce either scalar values or tables consisting of columns and rows of
data.
 Predicates which specify conditions that can be evaluated to SQL three-valued logic (3VL)
Boolean truth values and which are used to limit the effects of statements and queries, or to
change program flow.
 Queries which retrieve data based on specific criteria.
 Statements which may have a persistent effect on schemas and data, or which may control
transactions, program flow, connections, sessions, or diagnostics.
 SQL statements also include the semicolon (";") statement terminator. Though not required on
every platform, it is defined as a standard part of the SQL grammar.
 Insignificant white space is generally ignored in SQL statements and queries, making it easier to
format SQL code for readability.

There are five types of SQL statements. They are:

1. DATA DEFINITION LANGUAGE (DDL)


2. DATA MANIPULATION LANGUAGE (DML)
3. DATA RETRIEVAL LANGUAGE (DRL)
4. TRANSATIONAL CONTROL LANGUAGE (TCL)
5. DATA CONTROL LANGUAGE (DCL)

DATABASE MANAGEMENT
SYSTEMS(BCS403) 20
RV Institute of Technology and
Management®

1. DATA DEFINITION LANGUAGE (DDL): The Data Definition Language (DDL) is used to
create and destroy databases and database objects. These commands will primarily be used by
database administrators during the setup and removal phases of a database project.

Let's take a look at the structure and usage of four basic DDL commands:
1. CREATE 2. ALTER 3. DROP 4. RENAME

1. CREATE:
(a)CREATE TABLE: This is used to create a new relation (table)

Syntax: CREATE TABLE <relation_name/table_name > (field_1 data_type(size),field_2


data_type(size), .. . );

Example:
SQL> CREATE TABLE Student (sno NUMBER (3), sname CHAR (10), class CHAR (5));

2. ALTER:
(a) ALTER TABLE ...ADD...: This is used to add some extra fields into existing relation.

Syntax: ALTER TABLE relation_name ADD (new field_1 data_type(size), new field_2
data_type(size),..);
Example: SQL>ALTER TABLE std ADD (Address CHAR(10));

(b) ALTER TABLE...MODIFY...: This is used to change the width as well as data type of fields of
existing relations.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 21
RV Institute of Technology and
Management®

Syntax: ALTER TABLE relation_name MODIFY (field_1 newdata_type(Size), field_2


newdata_type(Size),... field_newdata_type(Size));
Example:SQL>ALTER TABLE student MODIFY(sname VARCHAR(10),class
VARCHAR(5));

c) ALTER TABLE..DROP This is used to remove any field of existing relations.


Syntax: ALTER TABLE relation_name DROP COLUMN (field_name);
Example:SQL>ALTER TABLE student DROP column (sname);

d) ALTER TABLE..RENAME...: This is used to change the name of fields in existing relations.
Syntax: ALTER TABLE relation_name RENAME COLUMN (OLD field_name) to (NEW
field_name);

Example: SQL>ALTER TABLE student RENAME COLUMN sname to stu_name;


3. DROP TABLE: This is used to delete the structure of a relation. It permanently deletes the
records in the table.
Syntax: DROP TABLE relation_name;
Example: SQL>DROP TABLE std;

4. RENAME: It is used to modify the name of the existing database object.


Syntax: RENAME TABLE old_relation_name TO new_relation_name;
Example: SQL>RENAME TABLE std TO std1;

Difference between Truncate & Delete:-


By using truncate command data will be removed permanently & will not get back where as by
using delete command data will be removed temporally & get back by using roll back command.
By using delete command data will be removed based on the condition where as by using
truncate command there is no condition.
Truncate is a DDL command & delete is a DML command.

DATABASE MANAGEMENT
SYSTEMS(BCS403) 22
RV Institute of Technology and
Management®

Implementation of different types of functions with suitable examples.


Number Function
Aggregate Function
Character Function
Conversion Function
Date Function

Objective:
NUMBER FUNCTION:

Abs(n) :Select abs(-15) from dual; Exp(n): Select exp(4) from dual; Power(m,n): Select power(4,2)
from dual; Mod(m,n): Select mod(10,3) from dual;
Round(m,n): Select round(100.256,2) from dual; Trunc(m,n): ;Select trunc(100.256,2) from dual;
Sqrt(m,n);Select sqrt(16) from dual;

Develop aggregate plan strategies to assist with summarization of several data entries.

Aggregative operators: In addition to simply retrieving data, we often want to perform some
computation or summarization. SQL allows the use of arithmetic expressions. We now consider
a powerful class of constructs for computing aggregate values such as MIN and SUM.

1. Count: COUNT following by a column name returns the count of tuple in that column. If
DISTINCT keyword is used then it will return only the count of unique tuple in the column.
Otherwise, it will return count of all the tuples (including duplicates) count (*) indicates all the
tuples of the column.
Syntax: COUNT (Column name)

DATABASE MANAGEMENT
SYSTEMS(BCS403) 23
RV Institute of Technology and
Management®

Example: SELECT COUNT (Sal) FROM emp;


2. SUM: SUM followed by a column name returns the sum of all the values in that
column. Syntax: SUM (Column name)
Example: SELECT SUM (Sal) From emp;

3. AVG: AVG followed by a column name returns the average value of that column
values. Syntax: AVG (n1, n2...)
Example: Select AVG (10, 15, 30) FROM DUAL;

4. MAX: MAX followed by a column name returns the maximum value of that
column. Syntax: MAX (Column name)
Example: SELECT MAX (Sal) FROM emp;
SQL> select deptno, max(sal) from emp group by deptno;

DEPTNO MAX (SAL)

10 5000
20 3000
30 2850
SQL> select deptno, max (sal) from emp group by deptno having max(sal)<3000; DEPTNO
MAX(SAL)

30 2850

5. MIN: MIN followed by column name returns the minimum value of that column.
Syntax: MIN (Column name)
Example: SELECT MIN (Sal) FROM emp;

DATABASE MANAGEMENT
SYSTEMS(BCS403) 24
RV Institute of Technology and
Management®

SQL>select deptno,min(sal) from emp group by deptno having min(sal)>1000;


DEPTNO MIN (SAL)
10 1300

CHARACTER FUNCTION:

initcap(char) : select initcap(“hello”) from dual; lower (char): select lower (‘HELLO’) from dual;
upper (char) :select upper (‘hello’) from dual;
ltrim (char,[set]): select ltrim (‘cseit’, ‘cse’) from dual; rtrim (char,[set]): select rtrim (‘cseit’, ‘it’)
from dual;
replace (char,search ): select replace(‘jack and jue’,‘j’,‘bl’) from dual;

CONVERSION FUNCTIONS:
To_char: TO_CHAR (number) converts n to a value of VARCHAR2 data type, using the optional
number format fmt. The value n can be of type NUMBER, BINARY_FLOAT, or
BINARY_DOUBLE.

SQL>select to_char(65,'RN')from dual; LXV


To_number : TO_NUMBER converts expr to a value of NUMBER data
type. SQL>Select to_number ('1234.64') from Dual; 1234.64

To_date:TO_DATE converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type to


a value of DATE data type.
SQL>SELECT TO_DATE('January 15, 1989, 11:00 A.M.')FROM DUAL; TO_DATE
15-JAN-89

STRING FUNCTIONS:

DATABASE MANAGEMENT
SYSTEMS(BCS403) 25
RV Institute of Technology and
Management®

Concat: CONCAT returns char1 concatenated with char2. Both char1 and char2 can be any of the
datatypes.
SQL>SELECT CONCAT(‘ORACLE’,’CORPORATION’)FROM DUAL;
ORACLECORPORATION

Lpad: LPAD returns expr1, left-padded to length n characters with the sequence of
characters in expr2.
SQL>SELECT LPAD(‘ORACLE’,15,’*’)FROM DUAL;
*********ORACLE
Rpad: RPAD returns expr1, right-padded to length n characters with expr2, replicated asmany
times as necessary.
SQL>SELECT RPAD (‘ORACLE’,15,’*’)FROM DUAL;
ORACLE*********

Ltrim: Returns a character expression after removing leading blanks.


SQL>SELECT LTRIM(‘SSMITHSS’,’S’)FROM DUAL;
MITHSS

Rtrim: Returns a character string after truncating all trailing blanks


SQL>SELECT RTRIM(‘SSMITHSS’,’S’)FROM DUAL;
SSMITH

Lower: Returns a character expression after converting uppercase character data to


lowercase.
SQL>SELECT LOWER(‘DBMS’)FROM DUAL;
dbms

Upper: Returns a character expression with lowercase character data converted to uppercase
SQL>SELECT UPPER(‘dbms’)FROM DUAL;
DBMS

Length: Returns the number of characters, rather than the number of bytes, of the givenstring
expression, excluding trailing blanks.
SQL>SELECT LENGTH(‘DATABASE’)FROM DUAL;8

DATABASE MANAGEMENT
SYSTEMS(BCS403) 26
RV Institute of Technology and
Management®

Substr: Returns part of a character, binary, text, or image expression.

SQL>SELECT SUBSTR(‘ABCDEFGHIJ’3,4)FROM DUAL;


CDEF

Instr: The INSTR functions search string for substring. The function returns an integer
indicating the position of the character in string that is the first character of this occurrence.SQL>SELECT
INSTR('CORPORATE FLOOR','OR',3,2)FROM DUAL;
14
DATE FUNCTIONS:
Sysdate:
SQL>SELECT SYSDATE FROMDUAL;
next_day:
SQL>SELECT NEXT_DAY(SYSDATE,’WED’)FROM DUAL
add_months:
SQL>SELECT ADD_MONTHS(SYSDATE,2)FROM DUAL;
last_day:
SQL>SELECT LAST_DAY(SYSDATE)FROM DUAL;
months_between:
SQL>SELECT MONTHS_BETWEEN(SYSDATE,HIREDATE)FROM EMP;
Least:
SQL>SELECT LEAST('10-JAN-07','12-OCT-07')FROM DUAL;
Greatest:
SQL>SELECT GREATEST('10-JAN-07','12-OCT-07')FROM DUAL;

DATABASE MANAGEMENT
SYSTEMS(BCS403) 27
RV Institute of Technology and
Management®

Lab Programs
Create a table called Employee & execute the following.
1 Employee(EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
1. Create a user and grant all permissions to theuser.
2. Insert the any three records in the employee table contains attributes EMPNO,ENAME JOB,
MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result.

SQL> CREATE TABLE Employee


( EMPNO INT,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MANAGER_NO INT,
SAL DECIMAL(10,2),
COMMISSION DECIMAL(10,2)
);
SQL>>>Table created successfully.

2. SQL>CREATE USER theuser IDENTIFIED BY 'password'; -- Change 'password' to


an appropriate password
GRANT ALL PRIVILEGES ON Employee TO the user;
SQL>>>User created successfully.
SQL>>>Privileges granted successfully.
3. INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL,
COMMISSION) VALUES
(1, 'John Doe', 'Manager', 101, 5000.00, 1000.00),
(2, 'Jane Smith', 'Developer', 101, 4000.00, 500.00),
(3, 'Alice Johnson', 'Analyst', 102, 3500.00, NULL);
SQL>>>3 rows inserted.

28
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

4. SQL>Adding primary key constraint and not null constraint to the Employee
table ALTER TABLE Employee
ADD CONSTRAINT PK_Employee_EMPNO PRIMARY KEY (EMPNO),
ADD CONSTRAINT CHK_SALARY CHECK (SAL > 0),
MODIFY ENAME VARCHAR(50) NOT
NULL, MODIFY JOB VARCHAR(50) NOT
NULL, MODIFY SAL DECIMAL(10,2) NOT
NULL;

SQL>>>Table altered successfully.

5. SQL>INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO,


SAL, COMMISSION)
VALUES (4, NULL, NULL, NULL, NULL, NULL);

2 Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR,SAL &
execute the following.
1. Add a column commission with domain to the Employeetable.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105

SQL>CREATE TABLE Employee


( EMPNO INT,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MGR INT,
SAL DECIMAL(10,2)
29
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

);

SQL>>>Table created successfully.

1. SQL> ALTER TABLE Employee


ADD COMMISSION DECIMAL(10,2);

SQL>>>Table altered successfully.

2. SQL>INSERT INTO Employee (EMPNO, ENAME, JOB, MGR, SAL,


COMMISSION) VALUES
(101, 'John Doe', 'Manager', 100, 5000.00, 1000.00),
(102, 'Jane Smith', 'Developer', 101, 4000.00, 500.00),
(103, 'Alice Johnson', 'Analyst', 101, 3500.00, NULL),
(104, 'Bob Williams', 'Designer', 102, 4500.00, 800.00),
(105, 'Charlie Brown', 'Assistant', 102, 3000.00, 200.00);

SQL>Select * from employee;

3. SQL>UPDATE
Employee SET JOB =
'Executive' WHERE
EMPNO = 105;

SQL>Select * from employee;

30
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

4. SQL>ALTER TABLE Employee


RENAME COLUMN MGR TO MANAGER_NO;

SQL>>>Table altered successfully.


5. SQL>DELETE FROM Employee
WHERE EMPNO = 105;

3 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.

1. SQL>CREATE TABLE Employee


( E_id INT PRIMARY KEY,
E_name VARCHAR(255),
Age INT,

31
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

Salary DECIMAL(10, 2) );

SQL>>>Table created successfully.

SQL> Describe Employee;

SQL>INSERT INTO Employee (E_id, E_name, Age,


Salary) VALUES
(2, 'Jane', 35, 60000.00),
(3, 'Alice', 28, 45000.00),
(4, 'Bob', 40, 55000.00);
(5, 'Max', 33, 60000.00),
(6, 'Srah', 27, 45000.00),
(7, 'Dravid', 25, 55000.00);
(8, 'Emily', 35, 60000.00),
(9, 'Mark', 28, 45000.00));

32
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

2. SQL>SELECT COUNT(E_name) AS TotalEmployees FROM Employee;

3. SQL>SELECT MAX(Age) AS MaxAge FROM Employee;

4. SELECT MIN(Age) AS MinAge FROM Employee;

5.SQL>SELECT E_name, Salary FROM Employee ORDER BY Salary ASC;

33
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

6. SQL> SELECT Salary, COUNT(*) AS Employee Count FROM Employee GROUP BY Salary;

4 Create a row level trigger for the customers table that would fire for INSERT or UPDATE or
DELETE operations performed on the CUSTOMERS table. This trigger will display the salary
difference between the old & new Salary. CUSTOMERS(ID, NAME, AGE, ADDRESS,
SALARY)

First Create table called customer and insert records into table

SQL> CREATE TABLE customers (


ID INT PRIMARY KEY,
NAME VARCHAR(255) NOT
NULL, AGE INT,
ADDRESS VARCHAR(255),

34
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

SALARY DECIMAL(10, 2)
);
SQL>>>Table created successfully.

SQL> describe customers;

SQL>INSERT INTO customers (ID, NAME, AGE, ADDRESS, SALARY)


VALUES
(2, 'Jane', 35, ‘Bangalore’,60000.00),
(3, 'Alice', 28, ‘Mysore’,45000.00),
(4, 'Bob', 40, ‘Ooty’,55000.00);
(5, 'Max', 33, ‘Delhi’,60000.00),
(6, 'Srah', 27, ‘Chennai’,45000.00),
(7, 'Dravid', 25, ‘Bangalore’,55000.00);
(8, 'Emily', 35, ‘Patna’,60000.00),
(9, 'Mark', 28, ‘Goa’,45000.00));

SQL> select * from customers;

Row Leevl Trigger:

35
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

SQL> CREATE TRIGGER salary_difference_trigger


AFTER INSERT OR UPDATE OR DELETE ON
customers FOR EACH ROW
BEGIN
DECLARE old_salary DECIMAL(10, 2);
DECLARE new_salary DECIMAL(10, 2);

IF INSERTING THEN
SET old_salary = NULL;
SET new_salary =
NEW.salary; ELSEIF
UPDATING THEN
SET old_salary = OLD.salary;
SET new_salary =
NEW.salary; ELSEIF
DELETING THEN
SET old_salary =
OLD.salary; SET new_salary
= NULL; END IF;

IF old_salary IS NOT NULL AND new_salary IS NOT NULL THEN


SELECT CONCAT('Salary difference for ', OLD.name, ': ', new_salary -
old_salary) AS 'Salary Difference';
ELSE
SELECT CONCAT('Salary difference for ', COALESCE(OLD.name,
NEW.name), ': Salary is either NULL or unchanged') AS 'Salary Difference';
END IF;
END;

SQL>>>Trigger created successfully.


5 Create cursor for Employee table & extract the values from the table. Declare the variables Open
the cursor & extrct the values from the cursor. Close the cursor. Employee(E_id, E_name, Age,
Salary)

First Create table called Employee and insert records into table
1. SQL>CREATE TABLE Employee
( E_id INT PRIMARY KEY,
E_name VARCHAR(255),
Age INT,
Salary DECIMAL(10, 2) );

SQL>>>Table created successfully.

SQL> Describe Employee;


36
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

SQL>INSERT INTO Employee (E_id, E_name, Age,


Salary) VALUES
(2, 'Jane', 35, 60000.00),
(3, 'Alice', 28, 45000.00),
(4, 'Bob', 40, 55000.00);
(5, 'Max', 33, 60000.00),
(6, 'Srah', 27, 45000.00),
(7, 'Dravid', 25, 55000.00);
(8, 'Emily', 35, 60000.00),
(9, 'Mark', 28, 45000.00));

SQL>
-- Declare variables to store cursor values
DECLARE emp_id INT;
DECLARE emp_name VARCHAR(255);
DECLARE emp_age INT;
DECLARE emp_salary DECIMAL(10, 2);

-- Declare cursor for Employee table


DECLARE emp_cursor CURSOR FOR
SELECT E_id, E_name, Age, Salary FROM Employee;

-- Open the cursor


OPEN emp_cursor;

-- Loop through cursor and extract values


emp_loop: LOOP
-- Fetch values from cursor into variables
FETCH emp_cursor INTO emp_id, emp_name, emp_age, emp_salary;

-- Check if no more rows to fetch, exit loop if so


IF (emp_id IS NULL) THEN
LEAVE emp_loop;

37
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

END IF;

-- Do something with the extracted values (print, manipulate, etc.)


-- For example, you can print the values
SELECT CONCAT('Employee ID: ', emp_id, ', Name: ', emp_name, ', Age: ', emp_age, ', Salary:
', emp_salary) AS 'Employee Info';

END LOOP emp_loop;

-- Close the cursor


CLOSE emp_cursor;

6 Write a PL/SQL block of code using parameterized Cursor, that will merge the data available in
the newly created table N_RollCall with the data available in the table O_RollCall. If the data in
the first table already exist in the second table then that data should be skipped.

SQL> DECLARE
-- Variables to store data from
N_RollCall n_id N_RollCall.ID%TYPE;
n_name N_RollCall.Name%TYPE;
n_date N_RollCall.Date%TYPE;
n_status N_RollCall.Status%TYPE;

-- Cursor for fetching data from N_RollCall


CURSOR n_cursor IS
SELECT ID, Name, Date,
Status FROM N_RollCall;

-- Variable to store count of skipped rows

38
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

skipped_rows NUMBER := 0;
BEGIN
-- Open the cursor
OPEN n_cursor;

-- Loop through each row in N_RollCall


LOOP
-- Fetch data from cursor into variables
FETCH n_cursor INTO n_id, n_name, n_date, n_status;

-- Exit loop if no more rows


EXIT WHEN n_cursor%NOTFOUND;

-- Check if the row exists in O_RollCall


SELECT COUNT(*)
INTO skipped_rows
FROM O_RollCall
WHERE ID = n_id
AND Name = n_name
AND Date = n_date
AND Status = n_status;

-- If row doesn't exist in O_RollCall, insert it


IF skipped_rows = 0 THEN
INSERT INTO O_RollCall (ID, Name, Date,
Status) VALUES (n_id, n_name, n_date, n_status);
END IF;

-- Reset skipped_rows variable


skipped_rows := 0;
END LOOP;

-- Close the cursor


CLOSE n_cursor;

-- Commit the transaction


COMMIT;

-- Display message indicating completion


DBMS_OUTPUT.PUT_LINE('Data merged
successfully.');
EXCEPTION
WHEN OTHERS THEN
-- Handle exceptions
DBMS_OUTPUT.PUT_LINE('Error: ' ||
SQLERRM);
39
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

ROLLBACK; -- Rollback transaction in case of error

31
0
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

END;

SQL>>Data merged successfully.

7 Install an Open Source NoSQL Data base MangoDB & perform basic CRUD(Create, Read,
Update & Delete) operations. Execute MangoDB basic Queries using CRUD operations

Install MongoDB:

Step:1 Download MongoDB Community Server from the official website: MongoDB Download
Center Follow the installation instructions provided for your operating system.
Start MongoDB Server:

Step: 2 After installation, start the MongoDB server. The method to start the server varies based on
your operating system. For example, on Windows, you can start it from the command line using
mongod, while on macOS or Linux, you can use sudo service mongod start.
Connect to MongoDB:

Step: 3 Open a terminal or command prompt and connect to the MongoDB server using the
mongo shell command. Perform CRUD Operations:

Step: 4 Once connected to the MongoDB server, you can perform basic CRUD operations using
the mongo shell or a MongoDB client like MongoDB Compass.

MangoDB basic Queries using CRUD operations

>>db.books.insertOne({ title: "MongoDB Basics", author: "John Doe", pages: 200 });

>>db.books.find({ author: "John Doe" });

40
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

> db.books.updateOne({ title: "MongoDB Basics" }, { $set: { pages: 250 } });

>db.books.deleteOne({ title: "MongoDB Basics" });

41
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

VIVA Question and Answers

1. What is database?

A database is a logically coherent collection of data with some inherent meaning,


representing some aspect ofreal world and which is designed, built and populated
with data for a specific purpose.

2. What is DBMS?

It is a collection of programs that enables user to create and maintain a database.


In other words itis general-purpose software that provides the users with the
processes of defining, constructing and manipulating the database for various
applications.

3. What is a Database system?

The database and DBMS software together is called as Database system.

4. What are the advantages of DBMS?

1. Redundancy is controlled.
2. Unauthorised access is restricted.
3. Providing multiple user interfaces.
4. Enforcing integrity constraints.
5. Providing backup and recovery.

5. What are the disadvantage in File Processing System?

1. Data redundancy and inconsistency.

42
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

2. Difficult in accessing data.


3. Data isolation.
4. Data integrity.
5. Concurrent access is not possible.
6. Security Problems.

6. Describe the three levels of data abstraction?

The are three levels of abstraction:

1. Physical level: The lowest level of abstraction describes how data are stored.

2. Logical level: The next higher level of abstraction, describes what


data are storedin database and what relationship among those data.
3. View level: The highest level of abstraction describes only part of
entire database.

7. Define the "integrity rules"?

There are two Integrity rules.


1. Entity Integrity: States that "Primary key cannot have NULL value"

2. Referential Integrity: States that "Foreign Key can be either a NULL


value or shouldbe Primary Key value of other relation.

8. What is Data Independence?

Data independence means that "the application is independent of the storage


structure andaccess strategy of data". In other words, The ability to modify the
schema definition in one level should not affect the schema definition in the next

43
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

higher level.
Two types of Data Independence:

1. Physical Data Independence: Modification in physical level


should not affect thelogical level.
2. Logical Data Independence: Modification in logical level should affect
the view level.

NOTE: Logical Data Independence is more difficult to achieve

9. What is a view? How it is related to data independence?

A view may be thought of as a virtual table, that is, a table that does not really
exist in its own right but is instead derived from one or more underlying base
table. In other words, there is no stored file that direct represents the view instead
a definition of view is stored in data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the
view can insulate users from the effects of restructuring and growth in the
database. Hence accounts for logicaldata independence.

10. What is Data Model?

A collection of conceptual tools for describing data, data relationships data


semantics and constraints.

11. What is E-R model?

This data model is based on real world that consists of basic objects called
entities and of relationship among these objects. Entities are described in
a database by a set of attributes.

44
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

12. What is Object Oriented model?

This model is based on collection of objects. An object contains values stored in


instance variableswith in the object. An object also contains bodies of code that
operate on the object. These bodiesof code are called methods. Objects that
contain same types of values and the same methods aregrouped together into
classes.

13. What is an Entity?

It is a 'thing' in the real world with an independent existence.

14. What is an Entity type?

It is a collection (set) of entities that have same attributes.

15. What is an Entity set?

It is a collection of all entities of particular entity type in the database.

16. What is an Extension of entity type?

The collections of entities of a particular entity type are grouped together into
an entity set.

17. What is Weak Entity set?

An entity set may not have sufficient attributes to form a primary key, and
its primary key compromises of its partial key and primary key of its parent
entity, then it is said to be WeakEntity set.

45
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

18. What is an attribute?

It is a particular property, which describes the entity.

19. What is a Relation Schema and a Relation?


A relation Schema denoted by R(A1, A2, ..., An) is made up of the relation
name R and the list of attributes Ai that it contains. A relation is defined as
a set of tuples. Let r be the relation which contains settuples (t1, t2, t3, ...,
tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).

20. What is degree of a Relation?

It is the number of attribute of its relation schema.

21. What is Relationship?

It is an association among two or more entities.

22. What is Relationship set?

The collection (or set) of similar relationships.

23. What is Relationship type?

Relationship type defines a set of associations or a relationship set among a given


set of entity types.

24. What is degree of Relationship type?

46
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

It is the number of entity type participating.

25. What is DDL (Data Definition Language)?

A data base schema is specifies by a set of definitions expressed by a


special language called DDL.

26. What is DML (Data Manipulation Language)?

This language that enable user to access or manipulate data as organised


by appropriate data model.

1. Procedural DML or Low level: DML requires a user to specify what


data are neededand how to get those data.

2. Non-Procedural DML or High level: DML requires a user to


specify what data areneeded without specifying how to get those data.

27. What is Query evaluation engine?

It executes low-level instruction generated by compiler.

28. What is normalization?

It is a process of analysing the given relation schemas based on their


Functional Dependencies(FDs) and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and
update anomalies.

47
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

29. What is Functional Dependency?

A Functional dependency is denoted by X Y between two sets of attributes X and


Y that are subsets of R specifies a constraint on the possible tuple that can form a
relation state r of R. The constraint is for any two tuples t1 and t2 in r if t1[X] =
t2[X] then they have t1[Y] = t2[Y]. This means the value of X component of a
tuple uniquely determines the value of component Y.

30. What is Lossless join property?

It guarantees that the spurious tuple generation does not occur with respect to
relation schemas after decomposition.

31. What is 1 NF (Normal Form)?

The domain of attribute must include only atomic (simple, indivisible) values.

32. What is Fully Functional dependency?

It is based on concept of full functional dependency. A functional dependency


X Y is full functional dependencyif removal of any attribute A from X means
that the dependency does not hold any more.

33. What is 2NF?

A relation schema R is in 2NF if it is in 1NF and every non-prime


attribute A in R is fullyfunctionally dependent on primary key.

34. What is 3NF?

48
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the


following is true

1. X is a Super-key of R.
2. A is a prime attribute of R.

In other words, if every non prime attribute is non-transitively dependent on


primary key.

35. What is BCNF (Boyce-Codd Normal Form)?

A relation schema R is in BCNF if it is in 3NF and satisfies an additional


constraint that for everyFD X A, X must be a candidate key.

36. What is meant by query optimization?

The phase that identifies an efficient execution plan for evaluating a


query that has theleast estimated cost is referred to as query
optimization.

37. What is durability in DBMS?


Once the DBMS informs the user that a transaction has successfully
completed, its effects shouldpersist even if the system crashes before all its
changes are reflected on disk. This property is called durability.

38. What do you mean by atomicity and aggregation?

1. Atomicity: Either all actions are carried out or none are. Users should
not have to worry about the effect of incomplete transactions. DBMS
ensures this by undoing the actions of incomplete transactions.

49
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

2. Aggregation: A concept which is used to model a relationship between a


collection of entities and relationships. It is used when we need to express a
relationship among relationships.

39. What is a query?

A query with respect to DBMS relates to user commands that are used to
interact with a data base. Thequery language can be classified into data
definition language and data manipulation language.

40. What do you mean by Correlated subquery?

Subqueries, or nested queries, are used to bring back a set of rows to be used
by the parent query. Depending on how the subquery is written, it can be
executed once for the parent query or it can be

executed once for each row returned by the parent query. If the subquery is
executed for eachrow of the parent, this is called a correlated subquery.

A correlated subquery can be easily identified if it contains any references to the


parent subquerycolumns in its WHERE clause. Columns from the subquery
cannot be referenced anywhere else inthe parent query. The following example
demonstrates a non-correlated subquery.

Example: SELECT * FROM CUST WHERE '10/03/1990' IN (SELECT


ODATE FROM ORDERWHERECUST.CNUM = ORDER.CNUM)

41. What are the primitive operations common to all record


management systems?

50
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

Addition, deletion and modification.

42. What are the unary operations in


Relational Algebra?

PROJECTION and SELECTION.

43. Are the resulting relations of PRODUCT and JOIN operation the same?

No.
PRODUCT: Concatenation of every row in one relation with every row in another.

JOIN: Concatenation of rows from one relation and related rows from another.

44. Which part of the RDBMS takes care of the data dictionary? How?

Data dictionary is a set of tables and database objects that is stored in a


special area of thedatabase and maintained exclusively by the kernel.

45. What is the job of the information stored in data-dictionary?


The information in the data dictionary validates the existence of the objects,
provides access tothem, and maps the actual physical storage location.

46. How do you communicate with an RDBMS?

You communicate with an RDBMS using Structured Query Language (SQL).

47. Define SQL and state the differences between SQL and other
conventionalprogramming Languages.

51
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

SQL is a nonprocedural language that is designed specifically for data access


operations on normalized relational database structures. The primary difference
between SQL and other conventional programming languages is that SQL
statements specify what data operations shouldbe performed rather than how to
perform them.

48. Name the three major set of files on disk that compose a database in Oracle.

There are three major sets of files on disk that compose a database. All the files
are binary. These are

1.) Database files


2.) Control files
3.) Redo logs

The most important of these are the database files where the actual data resides.
The control filesand the redo logs support the functioning of the architecture
itself. All three sets of files must be present, open, and available to Oracle for any
data on the database to be useable. Without these files, you cannot access the
database, and the database administrator might have to recover someor all of the
database using a backup, if there is one.

49. What is database Trigger?


A database trigger is a PL/SQL block that can defined to automatically execute
for insert, update, and delete statements against a table. The trigger can e defined
to execute once for the entire statement or once for every row that is inserted,
updated, or deleted. For any one table, there aretwelve events for which you can
define database triggers. A database trigger can call database procedures that are
also written in PL/SQL.

52
DATABASE MANAGEMENT SYSTEMS(BCS403)
RV Institute of Technology and
Management®

50. What is Transaction Manager?

It is a program module, which ensures that database, remains in a


consistent state despitesystem failures and concurrent transaction execution
proceeds without conflicting.

51. What is File Manager?

It is a program module, which manages the allocation of space on disk


storage and datastructure used to represent information stored on a disk.

52. What is Authorization and Integrity manager?

It is the program module, which tests for the satisfaction of


integrity constraint and checksthe authority of user to access data.

53. What are stand-alone procedures?

Procedures that are not part of a package are known as stand-alone because they
independently defined. These types of procedures are not available for reference
from other Oracle tools. Anotherlimitation of stand-alone procedures is that
they are compiled at run time, which slows execution.

54. What are cursors give different types of cursors?

PL/SQL uses cursors for all database information accesses statements.


The language supports theuse two types of cursors
1.) Implicit
2.) Explicit

53
DATABASE MANAGEMENT SYSTEMS(BCS403)

You might also like