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

DBMS Lab Record 2020-21

1) SQL is a language used to manage data in relational database management systems. It includes statements to query, manipulate, and define schemas and data. 2) There are five main types of SQL statements: DDL for defining database schemas, DML for manipulating data, DRL for retrieving data, TCL for transaction control, and DCL for controlling user access. 3) Program 1 demonstrates creating a database using DDL commands like CREATE DATABASE and reviewing it with SHOW DATABASE before deleting it using DROP DATABASE.

Uploaded by

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

DBMS Lab Record 2020-21

1) SQL is a language used to manage data in relational database management systems. It includes statements to query, manipulate, and define schemas and data. 2) There are five main types of SQL statements: DDL for defining database schemas, DML for manipulating data, DRL for retrieving data, TCL for transaction control, and DCL for controlling user access. 3) Program 1 demonstrates creating a database using DDL commands like CREATE DATABASE and reviewing it with SHOW DATABASE before deleting it using DROP DATABASE.

Uploaded by

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

PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
PC 263 CS: DATABASE MANAGEMENT (3VL) Boolean truth values and which are
SYSTEMS LAB used to limit the effects of statements and
Cumulative Record
(Lab Manual & Observation Book) queries, or to change program flow.
● Queries which retrieve data based on specific
Compiled By:-
K.Murali Krishna, N.Sabitha & G.Srishailam criteria.
Assistant Professor(s), CSED, MVSREC
● Statements which may have a persistent
SQL (Structured Query Language): effect on schemas and data, or which may
Structured Query Language is a database computer control transactions, program flow,
language designed for managing data in relational connections, sessions, or diagnostics.
database management systems(RDBMS), and ● SQL statements also include the semicolon
originally based upon Relational Algebra. Its scope (";") statement terminator. Though not
includes data query and update, schema creation and required on every platform, it is defined as a
modification, and data access control. SQL was one standard part of the SQL grammar.
of the first languages for Edgar F.Codd's relational ● Insignificant white space is generally ignored
model in his influential 1970 paper, "A Relational in SQL statements and queries, making it
Model of Data for Large Shared Data Banks" and easier to format SQL code for readability.
became the most widely used language for relational There are five types of SQL statements. They are:
databases. IBM developed SQL in the mid 1970's. 1. DATA DEFINITION LANGUAGE (DDL)
Oracle incorporated in 1979. SQL used by 2. DATA MANIPULATION LANGUAGE
IBM/DB2 and DS Database Systems. SQL was (DML)
adopted as the standard language for RDBS by ANSI 3. DATA RETRIEVAL LANGUAGE (DRL)
in 1989. 4. TRANSACTIONAL CONTROL
SQL language is subdivided into several language LANGUAGE (TCL)
elements, including: 5. DATA CONTROL LANGUAGE (DCL)
● Clauses, which are in some cases optional, DATA DEFINITION LANGUAGE (DDL):
constituent components of statements and The Data Definition Language (DDL) is used
queries. to create and destroy databases and database objects.
● Expressions, which can produce either scalar These commands will primarily be used by database
values or tables consisting of columns and administrators during the setup and removal phases
rows of data. of a database project. Let's take a look at the
● Predicates which specify conditions that can structure and usage of four basic DDL commands:
be evaluated to SQL three-valued logic 1. CREATE 2. ALTER 3. DROP 4. RENAME
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

DATA MANIPULATION LANGUAGE (DML):


The Data Manipulation Language (DML) is used to
retrieve, insert and modify database information.
These commands will be used by all database users
during the routine operation of the database. Let's
take a brief look at the basic DML commands:

1. INSERT 2. UPDATE 3. DELETE

DRL(DATA RETRIEVAL LANGUAGE): .


Retrieves data from one or more tables.
1. SELECT

TRANSACTIONAL CONTROL LANGUAGE


(TCL):
A transaction is a logical unit of work. All changes
made to the database can be referred to as a
transaction. Transaction changes can be mode
permanent to the database only if they are committed
a transaction begins with an executable SQL
statement & ends explicitly with either rollback or
commit statement.
1. COMMIT 2. ROLLBACK

DATA CONTROL LANGUAGE (D.C.L): DCL


provides users with privilege commands the owner
of database objects (tables), has the sole authority
over them. The owner (database administrators) can
allow other database uses to access the objects as per
their requirement
1.GRANT 2.REVOKE

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
Program 1 Pseudo code
CREATION OF DATABASE Select a database

To select a particular database to work with you


Problem Definition
issue the USE statement as follows:
Creation of database (exercising the commands for
creation) USE <database_name>;

Create a new database


Problem Description
Creating the structure of an entity is done by CREATE DATABASE [IF NOT EXISTS]
<database_name>;
using DDL commands. Data Definition Language
(DDL) commands are those commands that define Review the created database

either the structure of an object or the database in SHOW DATABASE <database_name>;


which the objects are stored. These commands
Delete an existing database in the server.
include the database creation, modification and
administration. DROP DATABASE [IF EXISTS]
<database_name>;

CREATE TABLE: This command defines all


Display Databases
characteristics of a table, including integrity and
Show databases;
check constraints, column names and data types,
storage option, and so on. Create Table Syntax

CREATE TABLE table_name ({column


Data in relational models is stored in tables. So the
datatype [column_constraints] |
first step is creating a table using SQL command
table_constraints} );
CREATE TABLE. Before a table is created the
CREATE TABLE table_name(
following factors are to be finalized.
column1datatype,
● The name of the table column2datatype,
● The number of columns in the table columnNdatatype,
● The name, data type and size of each column
PRIMARY KEY( one or more columns ),
of the table
Foreign Key( column ) References
● The column and table constraints.
tablename(column)
);

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
ALTER TABLE <table_name> ADD
<column_name datatype>;

ALTER TABLE <table_name> MODIFY


COLUMN <column_name datatype>;

ALTER TABLE <table_name> DROP COLUMN


<column_name>;

To list tables
Show tables;
TRUNCATE:
The SQL TRUNCATE TABLE command is used to
delete complete data from an existing table. The
basic syntax of a TRUNCATE TABLE command is
as follows.
TRUNCATE TABLE table_name;

TASK-1: Creation, altering and dropping


tables using SQL(DDL) Commands

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
To delete data from a table
DELETE FROM <table_name> WHERE
[condition];

Program 2
UPDATE <table_name> SET column1 = value1,
SIMPLE AND COMPLEX QUERIES
column2 = value, columnN = valueN WHERE
[condition];
Problem Definition
Transactional Control Language
Simple to complex condition query creation using
SQL Plus SAVEPOINT <savepoint-name>;

ROLLBACK;
Problem Description
SQL Plus commands are used fundamentally for COMMIT;

accessing and managing the data in the database. Integrity Constraints


Simple Queries: Simple Queries includes insert,
ALTER TABLE <table_name> ADD
select, update, alter, delete, drop, savepoint,
CONSTRAINT <MyPrimaryKey> PRIMARY
commit, rollback etc.
KEY (column1, column2.);
Complex Queries: Complex Queries includes
Joins, Subqueries, constraints, views etc. ALTER TABLE <table_name> ADD
CONSTRAINT <MyCheckConstraint> CHECK
Pseudo Code
(CONDITION);
Read data from one or more tables
ALTER TABLE <table_name> ADD
SELECT column1, column2, columnN FROM
CONSTRAINT <MyUniqueConstraint> UNIQUE
table_name;
(column1,column2….);
SELECT * FROM < table_name>;
ALTER TABLE <table_name> DROP
To insert new records in a table
CONSTRAINT <constraint-name>;
INSERT INTO <TABLE_NAME> VALUES
(value1,value2,value3,...valueN); SELECT <column_name> [, column_name ]

INSERT INTO <TABLE_NAME> (column1, col FROM <table1> [, table2 ] WHERE

umn2, …) VALUES (value1, value2, ...); <column_name> OPERATOR (SELECT


<column_name> [, column_name ] FROM table1

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
[, table2 ] [WHERE]); 5. Max()

SELECT <column1, column2> FROM <table1, An operator is a reserved word or a character used
table2> WHERE [conditions] GROUP BY primarily in an SQL statement WHERE clause to
column1, column2 HAVING [conditions] perform operation(s), such as comparisons and
ORDER BY column1, column2; arithmetic operations. These Operators are used to
specify conditions in an SQL statement and to
Order by : The order by clause is used to display
serve as conjunctions for multiple conditions in a
the results in sorted order.
statement.
Group by : The attribute or attributes given in the
1. Arithmetic operators
clauses are used to form groups. Tuples with the
2. Comparison operators
same value on all attributes in the group by clause
3. Logical operators
are placed in one group.
4. Operators used to negate conditions
Having: SQL applies predicates (conditions) in
the having clause after groups have been formed,
JOINS
so aggregate function be used.
SELECT <column_name(s)> FROM <table1>
INNER JOIN <table2> ON
Set Operations: UNION - OR INTERSECT -
table1.column_name=table2.column_name;
AND EXCEPT - - NOT
NESTED QUERY:- A nested query makes use of SELECT <column_name(s)> FROM <table1>
another sub-query to compute or retrieve the LEFT JOIN/RIGHT JOIN <table2> ON
information. table1.column_name=table2.column_name;

In database management an aggregate function is SELECT <column_name(s)> FROM <table1>

a function where the values of multiple rows are FULL OUTER JOIN <table2> ON

grouped together as input on certain criteria to table1.column_name=table2.column_name;

form a single value of more significant meaning.


CREATE VIEW <view_name> AS SELECT
Various Aggregate Functions
<column_name(s)> FROM <table_name>
1. Count()
WHERE [condition];
2. Sum()
3. Avg()
4. Min()

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Task-2.1: Write MySQL queries which use

Select
● distinct
● order by
● group by
Comparison operators
● Like, Not like
● > ,<.>=,<=,==,<>
● Between and, not between and
● In, not in
● Any, all
Aggregate functions
● Count, Sum, Average, Max, Min
Set Operations
● Union, Except, Intersect
Nested Queries
● Correlated

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Task-2.2:working of various kinds of join


operations in MySQL such as
● Cartesian Product
● Inner Join
○ Self Join
○ Equi join / Natural join
○ Non equi join
● Outer Join
○ Left
○ Right

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
evaluation to true.
Types of triggers
Row trigger: A row trigger is fired each time the
table is affected by a triggering statement. Eg: if
an update statement updates multiple rows of a
table, a row trigger is fired once for each row
affected by the update statement.
Statement trigger: A row trigger is fired once on
behalf of the triggering statement independent of
the number of rows the triggering statement
Program 3
affects.
TRIGGERS
Eg: If the trigger makes the security check on the
Problem Definition time or the user.
Using Triggers and stored procedures. Before trigger: It executes the trigger action
before the triggering statement is executed. Eg:
Problem Description Before triggers are used to derive specific column
Database Triggers are procedures that are stored in values before completing a triggering INSERT or
the database and are explicitly executed (fired) UPDATE statement.
where the contents of a table are changed. After trigger: It executes the trigger after the
Triggers have 3 basic parts. triggering statement is executed. After triggers are
1. Trigger event: It is a SQL statement that used when you want the triggering statement to
causes the trigger to be fired. It can insert, complete before executing the triggering action.
delete or update statements for a specified
table. Pseudo code
Create or replace trigger [Schema.]
2. Trigger restriction: It specifies a Boolean
(logical) expression that must be true for the <Triggername>
trigger to fire. It is specified using a where {Before | After}
clause. {Delete| Insert| Update [of column, -----] } On
3. Trigger action: It is a procedure that [Schema.] <tablename>
contains the SQL statement and Pl / SQL [Referencing {OLD as old, NEW as new} ] for
code to be executed when a triggering each row [ when condition ]
statement is issued and the trigger restriction Raise_application_error (error-no, ‘message’);
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
Syntax of deleting a trigger statement that you want to process.
Drop trigger trigger-name; ● Open the Cursor.
● Fetch the data from the cursor one row at a
time.
CURSOR: ● Close the cursor.

We have seen how oracle executes an SQL Explicit Cursor Attributes- Oracle provides
statement. Oracle DBA uses a work area for its certain attributes/ cursor variables to control the
internal processing. This work area is private to execution of the cursor. Whenever any
SQL’s operation and is called a cursor. cursor(explicit or implicit) is opened and used,
Oracle creates a set of four system variables via
The data that is stored in the cursor is called the
which Oracle keeps track of the ‘Current’ status of
Active Data set. The size of the cursor in memory
the cursor. You
is the size required to hold the number of rows in
the Active Data Set. ● Declare a cursor that specifies the SQL select
statement that you want to process.
● Open the Cursor.
● Fetch the data from the cursor one row at a
Explicit Cursor- You can explicitly declare a time.
cursor to process the rows individually. ● Close the cursor.

A cursor declared by the user is called Explicit How to Declare the Cursor:-

Cursor. For Queries that return more than one row, The General Syntax to create any particular cursor
You must declare a cursor explicitly. is as follows:-

The data that is stored in the cursor is called the Cursor <Cursorname> is Sql Statement;
Active Data set. The size of the cursor in memory How to Open the Cursor:-
is the size required to hold the number of rows in The General Syntax to Open any particular cursor
the Active is as follows:-

Why use an Explicit Cursor- Cursor can be used Open Cursorname;


when the user wants to process data one row at a
Fetching a record From the Cursor:-
time.
The fetch statement retrieves the rows from the
Explicit Cursor Management- The steps involved
active set to the variables one at a time.
in declaring a cursor and manipulating data in the
active data set are:- Each time a fetch is executed. The focus of the
DBA cursor advances to the next row in the Active
● Declare a cursor that specifies the SQL select
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
set. implicit cursor)

One can make use of any loop structure(Loop-End Table : Accounts(AcCNo, Name, Balance,
Loop along with While,For) to fetch the records DateofOpening, Branch)
from the cursor into one row at a time.

The General Syntax to Fetch the records from the


cursor is as follows:-

Fetch cursorname into variable1,variable2,______

Closing a Cursor:-

The General Syntax to Close the cursor is as


follows:-

Close <cursorname>;

Task 3.1:
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 values and
new values:

Task:3.2

Write a PL/SQL code that updates the balance


of the account holder of ‘Delhi’ branch and
displays the number of records updated. (Use
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

PROCEDURES

A procedure is a one kind of subprogram, which is


designed and created to perform a specific
operation on data in your database. A procedure
takes zero or more input parameters and returns
zero or more output parameters.
The syntax of a creation of procedure is as follows:
Syntax:
CREATE OR REPLACE PROCEDURE
procedure_name [(argument1 [IN/OUT/IN OUT]
datatype,
argument2 [IN/OUT/IN OUT] datatype,_)] IS
[<local variable declarations>]
BEGIN
Executable Statements
Program -4 [EXCEPTION
SUB PROGRAMS Optional Exception Handler(s)
]
A procedure or function that has been stored in the
END;
library cache is referred to as a stored procedure or
a stored function. A stored procedure or stored
The procedure is made up of two parts: the
function has the following characteristics:
declaration and the body of the procedure. The
● It has a name: This is the name by which the
declara- tion begins with the keyword
stored procedure or function is called and
PROCEDURE and ends with the last parameter
referenced.
declaration. The body begins with the keyword IS
● It takes parameters: These are the values sent
and ends with the keyword END.
to the stored procedure or function from the
The procedure body is further divided into
application.
three parts : declarative, executable and exception
● It returns values: A stored procedure or
parts are the same as PL/SQL blocks.
function can return one or more values based
The declaration section is used to assign
on the purpose of the procedure or function.
names and define parameter list, which variables
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
are passed to the procedure and which values are exception handlers and allowing the stored
returned from the procedure back to the calling procedure to notify you of some special conditions,
program. you can minimize the amount of return-value
Parameters can be defined in the following format checking that must be done in the application code.
Argument [parameter mode] datatype. There are Because the work to determine that no data has
three types of parameters mode: IN, OUT and IN been selected has already been done by the
OUT RDBMS engine, you can save on resources if you
IN Mode take advantage of this information
● Default parameter mode.
● Used to pass values to the procedure. Functions:
● Formal parameter can be a constant, literal, A function, like a procedure, is a set of PL/SQL
initialized variable or expression statements that form a subprogram. The
● Used for reading purpose subprogram is designed and created to perform a
OUT Mode specific operation on data. A function takes zero or
● Used to return values to the caller. more input parameters and returns just one output
● Formal parameters cannot be used in an value. If more than one output value is required, a
expression, but should be assigned a value. procedure should be used. The syntax of a function
● Used for writing purpose is as follows:
Syntax
IN OUT Mode CREATE OR REPLACE Function function_name
● Used to pass values to the procedure as well [(argument1 [IN/OUT/IN OUT] datatype,
as return values to the caller argument2 [IN/OUT/IN OUT] datatype,_)]
● Formal parameter acts like an initialized RETURN datatype IS
variable and should be assigned a value. [<local variable declarations>]
● Used for both reading and writing purpose BEGIN
PL/SQL Statements
The EXCEPTION Section
[EXCEPTION
In both procedures and functions, you can
Optional Exception Handler(s)]
add optional exception handlers. These exception
END [function_name];
handlers allow you to return additional information
/
based on certain conditions (such as no data found
As with a procedure, a function is made up of two
or some user-specified condition). By using
parts: the declaration and the body. The declaration
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
begins with the keyword Function and ends with
RETURN statement. The body begins with the
keyword IS and ends with the keyword END.
The difference between a procedure and a
function is the return value. A function has the
return declaration as well as a RETURN function
within the body of that function that returns a
value. This RETURN function is used to pass a
return value to the calling program.

Note: If you do not intend to return a value to the


calling program, or you want to return more than
one value, use a procedure.

Task 4.1: calculate the net salary and year salary if


da is 30% of basic, hra is 10% of basic and pf is 7%
if basic salary is less than 8000, pf is 10% if basic sal
between 8000 to 160000
Task 4.2: Print Fibonacci series using functions.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Program 5
FORM DESIGNING

Problem Definition
Creation of Forms using LibreOffice Base.

LibreOffice Base is a database management program, similar to Microsoft Access.

LibreOffice Base is a front end database manager that can be used to create forms and reports from a variety
of databases including MySql as well as others.

LibreOffice Base can be used to create small embedded databases when used with Java-based HSQLDB as
its storage engine (The LibreOffice Base default database). This makes LibreOffice Base appear as if it were
a database manager and the database, but it is not. LibreOffice Base is just the front end allowing us to tie
into the actual database.

Steps for creating a Form

The LibreOffice suite of tools includes a very powerful database application ─ one that happens to be
incredibly user-friendly. These databases can be managed/edited by any user and data can be entered by
anyone using a LibreOffice-generated form. These forms are very simple to create and can be attached to
existing databases or you can create both a database and a form in one fell swoop.

There are two ways to create LibreOffice Base forms:


❖ Form Wizard
❖ Design View.
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Design view is a versatile drag and drop form creator that is quite powerful and allows you to add elements
and assign those elements to database tables. The Form Wizard is a very simple step-by-step wizard that
walks the user through the process of creating a form. Although the Wizard isn’t nearly as powerful as the
Design View ─ it will get the job done quickly and doesn’t require any form of design experience.

For this entry, I will address the Form Wizard (in a later post, I will walk you through the more challenging
Design View). I will assume you already have a database created and ready for data entry. This database can
either be created with LibreOffice and reside on the local system or be a remote database of the format:

1. Oracle JDBC
2. Spreadsheet
3. dBASE
4. Text
5. MySQL
6. ODBC.

For purposes of simplicity, we’ll go with a local LibreOffice Base-generated database. I’ve created a very
simple database with two tables to be used for this process. Let’s create a data entry form for this database.

Opening the database


The first step is to open LibreOffice Base. When the Database Wizard window appears (Figure 1), select
Open an existing database file, click the Open button, navigate to the database to be used, and click Finish

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

The next window to appear is the heart and soul of LibreOffice Base. Here in Figure you can manage
tables, run queries, create/edit forms, and view reports of the opened database.

Click the Forms button in the left-side navigation and then double-click Use Wizard to Create Form under
Tasks.When the database opens in the Form Wizard, your first step is to select the fields available to the form.
You do not have to select all fields from the database. You can select them all or you can select as few as one.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
If your database has more than one table, you can select between the tables in the Tables or queries drop-down
(NOTE: You can only select fields from one table in the database at this point). Select the table to be used and
then add the fields from the Available fields section to the Fields in the form section in the Figure 3.

Once you’ve selected all the necessary fields, click Next. At this point, you can choose to add a subform. A
subform is a form-within-a-form and allows you to add more specific data to the original form. For example,
you can include secondary data for employee records (such as work history, raises, etc.) to a form. This is the
point at which you can include fields from other tables (besides the initial table selected from the Tables or
queries drop-down). If you opt to create a subform for your data, the steps include:

● Selecting the table


● Adding the fields
● Joining the fields (such as AuthorID to ID ─ Figure).

Arrange form controls

After all subforms are added, click Next to continue on. In the next step, you must arrange the controls of the
form. This is just another way of saying how you want the form to look and feel (where do you want the data
entry field to reside against the field label). You can have different layouts for forms and subforms .

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Select data entry mode

Click Next when you’ve arranged your controls. The next step is to select the data entry mode (Figure 6). There
are two data entry modes:

● Enter new data only


● Display all data.

If you want to use the form only as a means to enter new data, select Enter new data only. If, however, you
know you’ll want to use the form to enter and view data, select Display all data. If you go for the latter option,
you will want to select whether previously entered data can be modified or not. If you want to prevent write
access to the previous data, select Do not allow modification of existing data.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Make your selection and click Next. Start entering data

At this point you can select a style for your form. This allows you to pick a color and field border (no border,
3D border, or flat). Make your selection and click Next.

The last step is to name your form. In this same window you can select the option, immediately begin working
with the form (Figure 7). Select that option and click Finish. At this point, your form will open and you can start
entering data.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

After a form is created, and you’ve worked with and closed said form … how do you re-open a form to add
more data? Simple:

1. Open LibreOffice Base.


2. Open the existing database (in the same manner you did when creating the form).
3. Double-click the form name under Forms (Figure 8).
4. Start entering data.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
As a final note, make sure, after you finish working with your forms, that you click File > Save in the
LibreOffice Base main window, to ensure you save all of your work.
You can create as many forms as you need with a single database ─ there is no limit to what you can
do.
If you’re looking to easily enter data into LibreOffice databases, creating user-friendly forms is just a
few steps away. Next time we visit this topic, we’ll walk through the Design View method of form
creation.
Reports

Reports give you the ability to present information from your database in an easy-to-read, visually appealing
printable format. For example, you can create a simple report of phone numbers for all your contacts, or a
summary report on the total sales across different regions and time periods. Base makes it easy to create and
customize a report using data from any query or table in your database.

Creating Reports

In LibreOffice Base you can create a Report using

● Create a Report in Design View. Create a report from scratch.


● Use Wizard to Create Report. The Wizard guides you through a step by step process to create the report.
Unlike tables and queries, creating a report from scratch can be difficult for beginners. Therefore this is
the recommended method for to quickly and easily create a report.

Select the Use Wizard to Create Report. The Wizard opens a dialog window. In the following example we will
generate a report that displays all book's title, author and publishing date. The results will be grouped by author.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Step 1
In this step you select the Table Fields that you want the report to contain. In this example we select the Title,
Author and PublishingDate fields.

Step 2
The report generates a label for each field. By default Base chooses the field name for the label name. In our
example we change the "PublishingDate" field to "Publishing Date".

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Step 3
A report can group the results by one or more fields. In our example we choose to group the results by Author.

Step 4
As with queries, the results in reports can be sorted. By default results are sorted by the group field (Author).
You can specify more levels of sorting. Leave the default values.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Step 5
In this step we choose the Layout for the data and the headers and footers of the report. Click on the available
options to preview each layout.

Step 6
Here we specify the title and the type of the report. A dynamic report generates data from the current table data.
This means that if we update data on the table that feeds the report, the report will change accordingly.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

When you finish the wizard the report will be created and opened. The report is a text document and therefore it
opens using the Writer component of LibreOffice.

Managing a Report
To manage a Report first select the Reports Object from the Database Objects Pane and then select the report
from the Reports List. Use the Reports toolbar to Open, Edit, Delete or Rename a Report.

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

Editing a Report
A Report is basically a Writer document that acquires data from Base. Therefore you can edit a report like any
other Writer Document. For example you can change the alignment of the Publishing Date column. When you
edit a report you must save it using the Save Button from the Standard toolbar.

Task 5: Create forms and report for the student Information.


Program 6
PASSWORD AND SECURITY Problem Definition
FEATURES
Creating password and security features of
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
application. GRANT ALL PRIVILEGES [(column,
column,...)] ON [schema.]object TO grantee
Problem Description [WITH GRANT OPTION] [WITH HIERARCHY
All the core of security in the Oracle database user OPTION]
account, without an Oracle username there is no GRANT object_priv [(column, column,...)] ON
way that one can break into Oracle database. An DIRECTORY directory_name TO grantee [WITH
Oracle database typically has Number of Oracle GRANT OPTION] [WITH HIERARCHY
user accounts that were either created when the OPTION]
database was created or created later by the GRANT object_priv [(column, column,...)] ON
database administrator. Once created an Oracle user JAVA [RE]SOURCE [schema.]object TO grantee
has a number, and privileges that allow him to [WITH GRANT OPTION] [WITH HIERARCHY
create and modify database objects. OPTION]
Once an Oracle user is given a username and
password he can connect to Oracle database using grantee: user role PUBLIC
any to system_privs:
CREATE SESSION - Allows user to connect to
Pseudo code the database
(1) GRANT Statement Grant privileges to a user (or UNLIMITED TABLESPACE - Use an unlimited
to a user role) amount of any tablespace.
Syntax: SELECT ANY TABLE - Query tables, views, or
Grant System-wide Privs: mviews in any schema
GRANT system_priv(s) TO grantee [IDENTIFIED UPDATE ANY TABLE - Update rows in tables
BY password] [WITH ADMIN OPTION] and views in any schema
GRANT role TO grantee [IDENTIFIED BY INSERT ANY TABLE - Insert rows into tables
password] [WITH ADMIN OPTION] and views in any schema
GRANT ALL PRIVILEGES TO grantee Also System Admin rights to CREATE, ALTER
[IDENTIFIED BY password] [WITH ADMIN or DROP: cluster, context, database, link,
OPTION] dimension, directory, index,materialized view,
Grant privs on specific objects: operator, outline, procedure, profile, role, rollback
GRANT object_priv [(column, column,...)] segment, sequence, session, synonym, table,
ON [schema.]object TO grantee [WITH GRANT tablespace, trigger, type, user, view.
OPTION] [WITH HIERARCHY OPTION]
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
object_privs: users or roles. Syntax: Roles: REVOKE role
SELECT, UPDATE, INSERT, DELETE, FROM {user, | role, |PUBLIC} System Privs:
ALTER, DEBUG, EXECUTE, INDEX, REVOKE system_priv(s) FROM {user, | role, |
REFERENCES PUBLIC} REVOKE ALL FROM {user, | role, |
roles: PUBLIC} Object Privs: REVOKE object_priv
SYSDBA, SYSOPER, OSDBA, OSOPER, [(column1, column2..)] ON [schema.]object
EXP_FULL_DATABASE, FROM {user, | role, |PUBLIC} [CASCADE
IMP_FULL_DATABASE CONSTRAINTS] [FORCE]
SELECT_CATALOG_ROLE, REVOKE object_priv [(column1, column2..)] ON
EXECUTE_CATALOG_ROLE, [schema.]object FROM {user, | role, |PUBLIC}
DELETE_CATALOG_ROLE [CASCADE CONSTRAINTS] [FORCE]
AQ_USER_ROLE,
AQ_ADMINISTRATOR_ROLE - advanced REVOKE object_priv [(column1, column2..)] ON
queuing SNMPAGENT - Enterprise DIRECTORY directory_name FROM {user, |
Manager/Intelligent Agent. role, |PUBLIC} [CASCADE CONSTRAINTS]
RECOVERY_CATALOG_OWNER - rman [FORCE] REVOKE object_priv [(column1,
HS_ADMIN_ROLE - heterogeneous services column2..)] ON JAVA [RE]SOURCE
plus any user defined roles you have available. [schema.]object FROM {user, | role, |PUBLIC}
Note: Several Object_Privs can be assigned in a [CASCADE CONSTRAINTS] [FORCE] key:
single GRANT statement object_privs ALTER, DELETE, EXECUTE,
INDEX, INSERT, REFERENCES, SELECT,
WITH HIERARCHY OPTION will grant the UPDATE, ALL PRIVILEGES system_privs
object privilege on all subobjects, including any ALTER ANY INDEX, BECOME USER,
created after the GRANT statement is issued. CREATE TABLE, DROP ANY VIEW
WITH GRANT OPTION will enable the grantee RESTRICTED SESSION, UNLIMITED
to grant those object privileges to other users and TABLESPACE, UPDATE ANY TABLE plus too
roles. many others to list here
"GRANT ALL PRIVILEGES..." may also be roles Standard Oracle roles - SYSDBA,
written as "GRANT ALL..." SYSOPER, OSDBA, OSOPER,
EXP_FULL_DATABASE,
IMP_FULL_DATABASE plus any user defined
REVOKE Statement Revoke privileges from roles you have available FORCE, will revoke all
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
privileges from a user-defined-type and mark it's
dependent objects INVALID.

Drop user

Drop user username;

Task: Create Password and security features for


employee database

Program 7
TABLE LOCKING

Problem Definition
Usage of file locking, table locking facilities in
application

Problem Description

Oracle uses lock to control concurrent access to


data. Locks are mechanisms intended to prevent
destructive interaction between users accessing
the same data. Table locks lock the entire tables,
while row locks lock just selected rows. Thus
locks are used to ensure data integrity while

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
allowing max concurrent access to data by updating, inserting or deleting.
unlimited users.
SHARE ROW EXCLUSIVE They are used to
Locks are used to achieve two important goals. 1.
lock the whole table to selective update and to
Data concurrency
allow other users to lock a row in the table but not
2. Oracle lock is fully automatic and requires no
lock the table in share mode or to update rows.
user action .DBA locks the oracle data while
NO WAIT Indicates that you do not wish to wait
executing SQL statements. This type of locking is
if resources are unavailable. All locks are released
called implicit locking. When a lock is put by the
under the following circumstances:
user it is called explicit locking.
1. The transaction is committed successfully
Types of locks
2. A rollback is performed
Two levels of lock that a DBA can apply. They 3. A rollback to a save point will release locks
are set after specified save point
4. Row-level-locks are not released by rolling
1. Shared : Multi user can hold various share
back to a savepoint
lock on a single resource
5. Data locks are released by log off
2. Exclusive: It prohibits all sharing of
resources i.e. only one use has the sole
Task 7: Demonstrate MySQL locking
ability to alter the resources until locks are mechanism for cooperating table access
released. between sessions.

Pseudo code

LOCK TABLE [Table name] IN { ROW SHARE


| ROW EXCLUSIVE | SHARE UPDATE |
SHARE | SHARE ROW EXCLUSIVE |
EXCLUSIVE } MODE [ NOWAIT]
ROW SHARE Row share locks all concurrent
access to a table.

SHARE UPDATE They prohibit other users to


lock entire table exclusively

ROW EXCLUSIVE Row exclusive locks the


same as row share locks, but also prohibit locking
in share mode. These locks are acquired when
--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021
PC 263 CS: DATABASE MANAGEMENT SYSTEMS LAB
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-

--------------------------------------------------------------------------------------------------------------------------------------------------
BE IV SEM(AICTE) 2020-2021

You might also like