DBMS LAB MANUAL Updated
DBMS LAB MANUAL Updated
DBMS LAB MANUAL Updated
LABORATORY MANUAL
SEMESTER : V
SUBJECT :Database System Management Laboratories with Mini
Project.
SUBCODE :21CSL55
VISION
“Be a premier department in the field of Computer Science &
Engineering to meet the technological challenges of the
society”
Mission of the Department
MD 1 To provide state of the art infrastructure facilities
COURSE DETAILS
Course Name: DBMS Lab with Mini Project
COURSE OBJECTIVES
This course will enable students to
SYLLABUS
DBMS LABORATORY WITH MINI PROJECT
[As per Choice Based Credit System (CBCS) scheme]
Lab Experiments:
Part A: SQL Programming
A. Consider the following schema for a Library Database:
BOOK(Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS(Book_id, Author_Name)
PUBLISHER(Name, Address, Phone)
BOOK_COPIES(Book_id, Branch_id, No-of_Copies)
BOOK_LENDING(Book_id, Branch_id, Card_No, Date_Out, Due_Date)
LIBRARY_BRANCH(Branch_id, Branch_Name, Address)
Write SQL queries to
1. Retrieve details of all books in the library – id, title, name of publisher, authors, number of
copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017 to
Jun 2017.
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
4. Partition the BOOK table based on year of publication. Demonstrate its
working with a simple query.
5. Create a view of all books and its number of copies that are currently available in library.
Give these details only for 8th semester A, B, and C section students.
CO2 Create, populate , query and maintain tables of a database using PL/SQL
CO4 Develop database applications using front-end tools and back-end DBMS.
CO-PO Mapping
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 3 3 2
CO2 1 2 1
CO3 3 2 2 1
CO4 3 3 2 3
CO5 3 3 1 1
INTRODUCTION TO SQL
DATA DEFINITION, CONSTRAINTS, AND SCHEMA CHANGES
Used to CREATE, ALTER, and DROP the descriptions of the database tables (relations)
Data Definition in SQL
CREATE, ALTER and DROP
table….............................................................relation
row…...............................................................tuple
column…........................................................attribute
DATA TYPES
Numeric: NUMBER, NUMBER(s,p), INTEGER, INT, FLOAT, DECIMAL
Character: CHAR(n), VARCHAR(n), VARCHAR2(n), CHAR VARYING(n)
Bit String: BLOB, CLOB
Boolean: true, false, and null
Date and Time: DATE (YYYY-MM-DD) TIME( HH:MM:SS)
Timestamp: DATE + TIME
USER Defined types
CREATE SCHEMA
Specifies a new database schema by giving it a name
Ex: CREATE SCHEMA COMPANY AUTHORIZATION Jsmith;
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> ( <Attribute A1> <Data Type D1> [< Constarints>],
<Attribute A2> <Data Type D2> [< Constarints>],
Specifying the unique, primary key attributes, secondary keys, and referential integrity
constraints (foreign keys).
Ex: CREATE TABLE DEPT (
DNAME VARCHAR(10) NOT NULL,
DNUMBER INTEGER NOT NULL,
MGRSSN CHAR(9),
MGRSTARTDATE CHAR(9),
PRIMARY KEY (DNUMBER),
UNIQUE (DNAME),
FOREIGN KEY (MGRSSN) REFERENCES EMP(SSN));
We can specify RESTRICT, CASCADE, SET NULL or SET DEFAULT on referential
integrity constraints (foreign keys)
Ex: CREATE TABLE DEPT (
DNAME VARCHAR(10) NOT NULL,
DNUMBER INTEGER NOT NULL,
MGRSSN CHAR(9), MGRSTARTDATE CHAR(9),
PRIMARY KEY (DNUMBER),
UNIQUE (DNAME),
FOREIGN KEY (MGRSSN) REFERENCES EMP
ON DELETE SET DEFAULT ON UPDATE CASCADE);
DROP TABLE
Used to remove a relation (base table) and its definition.
The relation can no longer be used in queries, updates, or any other commands since its
description no longer exists
Example: DROP TABLE DEPENDENT;
ALTER TABLE:
Used to add an attribute to/from one of the base relations drop constraint -- The new
attribute will have NULLs in all the tuples of the relation right after the command is
executed; hence, the NOT NULL constraint is not allowed for such an attribute.
Example: ALTER TABLE EMPLOYEE ADD JOB VARCHAR2 (12);
The database users must still enter a value for the new attribute JOB for each
EMPLOYEE tuple. This can be done using the UPDATE command.
DROP A COLUMN (AN ATTRIBUTE)
ALTER TABLE COMPANY.EMPLOYEE DROP ADDRESS CASCADE; All
constraints and views that reference the column are dropped automatically, along with the
column. ALTER TABLE COMPANY.EMPLOYEE DROP ADDRESS RESTRICT;
Successful if no views or constraints reference the column. ALTER TABLE
COMPANY.DEPARTMENT ALTER MGRSSN DROP DEFAULT;
LAB EXPERIMENTS
PART A: SQL PROGRAMMING
Table Creation
Table Descriptions
DESC PUBLISHER;
DESC BOOK;
DESC BOOK_AUTHORS;
DESC LIBRARY_BRANCH;
DESC BOOK_COPIES;
DESC BOOK_LENDING;
Queries:
1. Retrieve details of all books in the library – id, title, name of publisher, authors,
number of copies in each branch, etc.
SELECT B.BOOK_ID, B.TITLE, B.PUBLISHER_NAME, A.AUTHOR_NAME,
C.NO_OF_COPIES, L.BRANCH_ID
FROM BOOK B, BOOK_AUTHORS A, BOOK_COPIES C, LIBRARY_BRANCH L
WHERE B.BOOK_ID=A.BOOK_ID
AND B.BOOK_ID=C.BOOK_ID
AND L.BRANCH_ID=C.BRANCH_ID;
2. Get the particulars of borrowers who have borrowed more than 3 books, but from
Jan 2017 to Jun 2017.
SELECT CARD_NO
FROM BOOK_LENDING
WHERE DATE_OUT BETWEEN ’01-JAN-2017’ AND ’01-JUL-2017’
GROUP BY CARD_NO
HAVING COUNT (*)>3;
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
DELETE FROM BOOK
WHERE BOOK_ID=3;
4. Partition the BOOK table based on year of publication. Demonstrate its working with a
simple query.
CREATE VIEW V_PUBLICATION AS
SELECT PUB_YEAR
FROM BOOK;
5. Create a view of all books and its number of copies that are currently available in the
Library.
CREATE VIEW V_BOOKS AS
SELECT B.BOOK_ID, B.TITLE, C.NO_OF_COPIES
FROM BOOK B, BOOK_COPIES C, LIBRARY_BRANCH L
WHERE B.BOOK_ID=C.BOOK_ID
AND C.BRANCH_ID=L.BRANCH_ID;
Solution:
Schema Diagram
Salesman
Customer
Order
s
Ord_No Purchase_Amt Ord_Date Customer_id Salesman_id
Table Creation
Table Descriptions
DESC SALESMAN;
DESC CUSTOMER1;
DESC ORDERS;
Queries:
1. Count the customers with grades above Bangalore’s average.
SELECT GRADE, COUNT (DISTINCT CUSTOMER_ID)
FROM CUSTOMER1
GROUP BY GRADE
2. Find the name and numbers of all salesmen who had more than one customer.
SELECT SALESMAN_ID, NAME
FROM SALESMAN A
WHERE 1 < (SELECT COUNT (*)
FROM CUSTOMER1
WHERE SALESMAN_ID=A.SALESMAN_ID);
3. List all salesmen and indicate those who have and don’t have customers in their
cities (Use UNION operation.)
SELECT SALESMAN.SALESMAN_ID, NAME, CUST_NAME, COMMISSION
FROM SALESMAN, CUSTOMER1
WHERE SALESMAN.CITY = CUSTOMER1.CITY
UNION
SELECT SALESMAN_ID, NAME, 'NO MATCH', COMMISSION
FROM SALESMAN
WHERE NOT CITY = ANY
(SELECT CITY
FROM CUSTOMER1)
ORDER BY 2 DESC;
4. Create a view that finds the salesman who has the customer with the highest order
of a day.
5. Demonstrate the DELETE operation by removing salesman with id 1000. All his orders
must also be deleted.
Use ON DELETE CASCADE at the end of foreign key definitions while creating child table
orders and then execute the following:
Use ON DELETE SET NULL at the end of foreign key definitions while creating child table
customers and then executes the following:
Director
Dir_id Dir_Name Dir_Phone
Movies
Mov_id Mov_Title Mov_Year Mov_Lang Dir_id
Movie_Cast
Act_idMov_idRole
Rating
Mov_idRev_Stars
Table Creation
CREATE TABLE ACTOR (
ACT_ID NUMBER (3),
ACT_NAME VARCHAR (20),
ACT_GENDER CHAR (1),
PRIMARY KEY (ACT_ID));
DESC DIRECTOR;
DESC MOVIES;
DESC MOVIE_CAST;
DESC RATING;
Queries:
1. List the titles of all movies directed by ‘Hitchcock’.
SELECT MOV_TITLE
FROM MOVIES
WHERE DIR_ID IN (SELECT DIR_ID
FROM DIRECTOR
WHERE DIR_NAME = ‘HITCHCOCK’);
2. Find the movie names where one or more actors acted in two or more movies.
SELECT MOV_TITLE
FROM MOVIES M, MOVIE_CAST MV
WHERE M.MOV_ID=MV.MOV_ID AND ACT_ID IN (SELECT ACT_ID
FROM MOVIE_CAST GROUP BY ACT_ID
HAVING COUNT (ACT_ID)>1)
GROUP BY MOV_TITLE
HAVING COUNT (*)>1;
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use
JOIN operation).
SELECT ACT_NAME, MOV_TITLE, MOV_YEAR
FROM ACTOR A
JOIN MOVIE_CAST C
ON A.ACT_ID=C.ACT_ID
JOIN MOVIES M
ON C.MOV_ID=M.MOV_ID
WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
OR
SELECT A.ACT_NAME, A.ACT_NAME, C.MOV_TITLE, C.MOV_YEAR
FROM ACTOR A, MOVIE_CAST B, MOVIES C
WHERE A.ACT_ID=B.ACT_ID
AND B.MOV_ID=C.MOV_ID
AND C.MOV_YEAR NOT BETWEEN 2000 AND 2015;
4. Find the title of movies and number of stars for each movie that has at least one
rating and find the highest number of stars that movie received. Sort the result by
movie title.
Table Creation
Table Descriptions
DESC STUDENT;
DESC SEMSEC;
DESC CLASS;
DESC SUBJECT;
DESC IAMARKS;
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES
('1RN13CS091','10CS81','CSE8C', 15, 16, 18);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES
('1RN13CS091','10CS82','CSE8C', 12, 19, 14);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES
('1RN13CS091','10CS83','CSE8C', 19, 15, 20);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES
('1RN13CS091','10CS84','CSE8C', 20, 16, 19);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES
('1RN13CS091','10CS85','CSE8C', 15, 15, 12);
Queries:
1. List all the student details studying in fourth semester ‘C’ section.
SELECT S.*, SS.SEM, SS.SEC
FROM STUDENT S, SEMSEC SS, CLASS C
WHERE S.USN = C.USN AND
SS.SSID = C.SSID AND
SS.SEM = 4 AND
SS.SEc=’C’;
2. Compute the total number of male and female students in each semester and in each
section.
4. Calculate the Final IA (average of best two test marks) and update the corresponding
table for all students.
CREATE OR REPLACE PROCEDURE AVGMARKS
IS
CURSOR C_IAMARKS IS
SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B,
GREATEST(TEST3,TEST2) AS C
FROM IAMARKS
WHERE FINALIA IS NULL
FOR UPDATE;
C_A NUMBER;
C_B NUMBER;
C_C NUMBER;
C_SM NUMBER;
C_AV NUMBER;
BEGIN
OPEN C_IAMARKS;
LOOP
FETCH C_IAMARKS INTO C_A, C_B, C_C;
EXIT WHEN C_IAMARKS%NOTFOUND;
--DBMS_OUTPUT.PUT_LINE(C_A || ' ' || C_B || ' ' || C_C);
IF (C_A != C_B) THEN
C_SM:=C_A+C_B;
ELSE
C_SM:=C_A+C_C;
END IF;
C_AV:=C_SM/2;
--DBMS_OUTPUT.PUT_LINE('SUM = '||C_SM);
--DBMS_OUTPUT.PUT_LINE('AVERAGE = '||C_AV);
UPDATE IAMARKS SET FINALIA=C_AV WHERE CURRENT OF C_IAMARKS;
END LOOP;
CLOSE C_IAMARKS;
END;
/
Note: Before execution of PL/SQL procedure, IAMARKS table contents are:
Below SQL code is to invoke the PL/SQL stored procedure from the command line:
BEGIN
AVGMARKS;
END;
SELECT S.USN,S.SNAME,S.ADDRESS,S.PHONE,S.GENDER,
(CASE
Department
DLocation
DNODLOC
Project
Works_on
Table Creation
Table Descriptions
DESC EMPLOYEE;
DESC DEPARTMENT;
DESC DLOCATION;
DESC PROJECT;
DESC WORKS_ON;
Note: update entries of employee table to fill missing fields SUPERSSN and DNO
SUPERSSN=’RNSCSE03’, DNO=’5’
WHERE SSN=’RNSCSE02’;
Queries:
1. Make a list of all project numbers for projects that involve an employee whose last
name is ‘Scott’, either as a worker or as a manager of the department that controls the
project.
(SELECT DISTINCT P.PNO
FROM PROJECT P, DEPARTMENT D, EMPLOYEE E
WHERE E.DNO=D.DNO
AND D.MGRSSN=E.SSN
AND E.LNAME=’SCOTT’)
UNION
(SELECT DISTINCT P1.PNO
FROM PROJECT P1, WORKS_ON W, EMPLOYEE E1
WHERE P1.PNO=W.PNO
AND E1.SSN=W.SSN
AND E1.LNAME=’SCOTT’);
2. Show the resulting salaries if every employee working on the ‘IoT’ project is given a 10
percent raise.
SELECT E.FNAME, E.LNAME, 1.1*E.SALARY AS INCR_SAL
FROM EMPLOYEE E, WORKS_ON W, PROJECT P
WHERE E.SSN=W.SSN
AND W.PNO=P.PNO
AND P.PNAME=’IOT’;
3. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well as
the maximum salary, the minimum salary, and the average salary in this department
WHERE E.DNO=D.DNO
AND D.DNAME=’ACCOUNTS’;
4. Retrieve the name of each employee who works on all the projects Controlled by
department number 5 (use NOT EXISTS operator).
SELECT E.FNAME, E.LNAME
FROM EMPLOYEE E
WHERE NOT EXISTS((SELECT PNO
FROM PROJECT
WHERE DNO=’5’)
MINUS (SELECT PNO
FROM WORKS_ON
WHERE E.SSN=SSN));
5. For each department that has more than five employees, retrieve the department
number and the number of its employees who are making more than Rs. 6, 00,000.
1. What is SQL?
Structured Query Language
2. What is database?
A database is a logically coherent collection of data with some inherent meaning,
representing some aspect of real world and which is designed, built and populated with data
for a specific purpose.
3. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other
words it is general-purpose software that provides the users with the processes of defining,
constructing and manipulating the database for various applications.
4. What is a Database system?
The database and DBMS software together is called as Database system.
5. Advantages of DBMS?
Redundancy is controlled.
Unauthorized access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.
6. Disadvantage in File Processing System?
Data redundancy & inconsistency.
Difficult in accessing data.
Data isolation.
Data integrity.
Concurrent access is not possible.
Security Problems.
7. Describe the three levels of data abstraction?
There are three levels of abstraction:
Physical level: The lowest level of abstraction describes how data are stored.
Logical level: The next higher level of abstraction, describes what data are stored in
database and what relationship among those data.
View level:The highest level of abstraction describes only part of entire database.
8. Define the "integrity rules"
There are two Integrity rules.
Entity Integrity:States that “Primary key cannot have NULL value”
Referential Integrity:States that “Foreign Key can be either a NULL value or
should be Primary Key value of other relation.
9. What is extension and intension?
Extension - It is the number of tuples present in a table at any instance. This is time
dependent.
Intension -It is a constant value that gives the name, structure of table and the constraints laid
on it.
10. What is Data Independence?
Data independence means that “the application is independent of the storage structure and
access 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 higher level.
Two types of Data Independence:
Physical Data Independence: Modification in physical level should not affect the
logical level.
Logical Data Independence: Modification in logical level should affect the view
level.
NOTE: Logical Data Independence is more difficult to achieve
11. 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
logical data independence.
A relation schema R is in BCNF if it is in 3NF and satisfies additional constraints that for
every FD X A, X must be a candidate key.
41. What is 4NF?
A relation schema R is said to be in 4NF if for every Multivalued dependency X Y
that holds over R, one of following is true
X is subset or equal to (or) XY = R.
X is a super key.
42. What is 5NF?
A Relation schema R is said to be 5NF if for every join dependency {R1, R2, ...,Rn} that
holds R, one the following is true
Ri = R for some i.
The join dependency is implied by the set of FD, over R in which the left side is key of R.
43. What is Domain-Key Normal Form?
A relation is said to be in DKNF if all constraints and dependencies that should hold on the
constraint can be enforced by simply enforcing the domain constraint and key constraint on the
relation.
44. What is a Partial key and Compound key?
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to
same owner entity. It is sometime called as Discriminator.
Compound Key:
If no single data element uniquely identifies occurrences within a construct, then
combining multiple elements to create a unique identifier for the construct is known as creating a
compound key.
45. What is system catalog or catalog relation? How is better known as?
A RDBMS maintains a description of all the data that it contains, information about
every relation and index that it contains. This information is stored in a collection of relations
maintained by the system called metadata. It is also called data dictionary.
46. What is join dependency and inclusion dependency?
Join Dependency:
Undo phase
52. What do you mean by flat file database?
It is a database in which there are no programs or user access languages. It has no cross-
file capabilities but is user-friendly and provides user-interface management.
53. What is "transparent DBMS"?
It is one, which keeps its Physical Structure hidden from user.
54. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a
data base. The query language can be classified into data definition language and data
manipulation language.
55. 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 each row of the parent, this is called a correlated subquery.
56. What are the primitive operations common to all record management systems?
Addition, deletion and modification.
57. What are the unary operations in Relational Algebra?
PROJECTION and SELECTION.
58. 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.
59. Name the sub-systems of a RDBMS
I/O, Security, Language Processing, Process Control, Storage Management, Logging and
Recovery, Distribution Control, Transaction Control, Memory Management, Lock Management
60. 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 the
database and maintained exclusively by the kernel.
61. 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 to them, and maps the actual
physical storage location.
62. How do you communicate with an RDBMS?
You communicate with an RDBMS using Structured Query Language (SQL)
63. Define SQL and state the differences between SQL and other conventional
programming Languages
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 should
be performed rather than how to perform them.
64. 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
Database files
Control files
Redo logs
The most important of these are the database files where the actual data resides. The
control files and 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 some or all of the database using a backup, if there is one.
65. What is ROWID?
The ROWID is a unique database-wide physical address for every row on every table.
Once assigned (when the row is first inserted into the database), it never changes until the row is
deleted or the table is dropped.
The ROWID consists of the following three components, the combination of which
uniquely identifies the physical storage location of the row.
Oracle database file number, which contains the block with the rows
Oracle block address, which contains the row
The row within the block (because each block can hold many rows)
The ROWID is used internally in indexes as a quick means of retrieving rows with a
particular key value. Application developers also use it in SQL statements as a quick way to
access a row once they know the ROWID
66. 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 are twelve events for which you can define database triggers. A database trigger can call
database procedures that are also written in PL/SQL.
67. What are stored-procedures? And what are the advantages of using them.
Stored procedures are database objects that perform a user defined operation. A stored
procedure can have a set of compound SQL statements. A stored procedure executes the SQL
commands and returns the result to the client. Stored procedures are used to reduce network
traffic.
68. Spurious tuples may occur due to
i. Bad normalization
ii. Theta joins
iii. Updating tables from join
a) i& ii b) ii & iii
c) i& iii d) ii & iii
(a) i& iii because theta joins are joins made on keys that are not primary keys.
69. A dominant entity is the entity
a) on the N side in a 1 : N relationship
b) on the 1 side in a 1 : N relationship
c) on either side in a 1 : 1 relationship
d) nothing to do with 1 : 1 or 1 : N relationship
(b) on the 1 side in a 1 : N relationship
70. What is Storage Manager?
It is a program module that provides the interface between the low-level data stored in
database, application programs and queries submitted to the system.
71. What is Buffer Manager?
It is a program module, which is responsible for fetching data from disk storage into main
memory and deciding what data to be cache in memory.
72. What is Transaction Manager?
It is a program module, which ensures that database, remains in a consistent state despite
system failures and concurrent transaction execution proceeds without conflicting.
73. What is File Manager?
It is a program module, which manages the allocation of space on disk storage and data
structure used to represent information stored on a disk.
74. What is Authorization and Integrity manager?
It is the program module, which tests for the satisfaction of integrity constraint and
checks the authority of user to access data.
75. What are stand-alone procedures?
Procedures that are not part of a package are known as stand-alone because they
independently defined. A good example of a stand-alone procedure is one written in a
SQL*Forms application. These types of procedures are not available for reference from other
Oracle tools. Another limitation of stand-alone procedures is that they are compiled at run time,
which slows execution.
76. What are cursors give different types of cursors.
PL/SQL uses cursors for all database information accesses statements. The language
supports the use two types of cursors
Implicit
Explicit
77. What do you understand by dependency preservation?
Given a relation R and a set of FDs F, dependency preservation states that the
closure of the union of the projection of F on each decomposed relation Ri is equal to the
closure of F. i.e.,
((R1(F)) U … U (Rn(F)))+= F+
if decomposition is not dependency preserving, then some dependency is lost in the
decomposition.
Part A. For connecting java application with the mysql database, you need to follow 5 steps to
perform database connectivity.
In this example we are using MySql as the database. So we need to know following informations
for the mysql database:
1. Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.
2. Connection URL: The connection URL for the mysql database
is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is the database,
localhost is the server name on which mysql is running, we may also use IP address, 3306
is the port number and sonoo is the database name. We may use any database, in such
case, you need to replace the sonoo with your database name.
3. Username: The default username for the mysql database is root.
4. Password: Password is given by the user at the time of installing the mysql database. In
this example, we are going to use root as the password.
Let's first create a table in the mysql database, but before creating table, we need to create
database first.
1. create database sonoo;
2. use sonoo;
3. create table emp(id int(10),name varchar(40),age int(3));
In this example, sonoo is the database name, root is the username and password.
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{ Class.forName("com.mysql.jdbc.Dri
ver");
Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/sonoo","root","ro
ot"); //here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}}
To connect java application with the mysql database mysqlconnector.jar file is required to be
loaded.
PL/SQL Loop
The PL/SQL loops are used to repeat the execution of one or more statements for specified
number of times. These are also known as iterative control statements.