DBMS-notes-2
DBMS-notes-2
It can be downloaded from www.libreoffice.org and is available for both Linux and Windows
operating systems. The data types of the fields have to be specified while creating tables in a
database. Thereafter valid data is entered and stored in a table.
A data type refers to the type of data that will be stored in that particular field.
The memory size of a field varies according to its data type.
Date Data Type – This data type is used to indicate dates and time
Currency Data Type –
The currency data type indicates the monetary values can be stored using currencies of various
countries. For example$100, £ 500 or Rs. 25.50.
Date Stores the year, month and day as it is stored in the system.
Time Stores the time of the day as hour, minute and second.
Timestamp Stores date and time information at once.
Boolean –
In boolean data type there can be only two values- True or False.
This also can be given in multiple formats like Yes/No, True/False, On/Off.
Binary –
The Binary data type used to store digitized images and sounds that comes as long string of zeros and
ones.
It is possible to store photos of the products or employees, or sound snippets or voice messages in
Base database.
A table in LibreOffice Base can be created using a wizard or using the Design view.
SCREEN ELEMENTS
Title Bar
displays the name of a database and an application in which it is made.
The windows buttons to maximize, minimize or close the window are located on the right corner of
the title bar.
Menu Bar
The menu bar appears below the title bar.
It consists of seven menu items – File, Edit, View, Insert, Tools, Window and Help.
All these menu items contain commands that help to perform various operations on the database.
Standard Toolbar –
It is located below the menu bar.
It is used to access frequently used tools.
Status Bar
It is located at the bottom of the interface window.
It displays information about the type of view of the object in the database.
Database Pane
The database pane is located on the left side of the window.
Depending on the object that is selected, the respective Task Pane and Object Area displaying the
created object( Tables, Forms, Queries, Reports and application modules )appears.
To make a particular field as the primary key, place the mouse pointer before the field name and
right click.
To set a composite key, i.e. a primary key consisting of two fields, keep the Ctrl key pressed and then
click on multiple fields to select them. Thereafter right click on selected fields and choose Primary
Key option from the pop up menu.
Record Selector Box – T his is the text box where the currently active record number is displayed. We
may enter the record number that we want to see in this text box.
The record for a particular entity should neither be repeated nor different data values should appear
for a single entity in the database.
This is done by setting relationship between the tables of a database. The most important
prerequisite for setting a relationship is that there must be a common field(s) between the two
tables to create a relationship.
Once the relationship between the two tables has been set, the integrity of data will be managed by
the DBMS.
Types of Relationships
The type of relationship between any two tables in a database is based on the number of records
that are present in the transaction table corresponding to the master table. Primarily three types of
relationships can be set up between two tables in a relational database These are:
(i) One-to-One
(ii) One-to-many
(iii) Many-to-Many
One-to-One relationship
In this type of relationship, one specific record of a master table has one and only one
corresponding record in the transaction table.
One-to-Many relationship
This is one of the most common types of relationship between the tables in a database. As
the name says, in this type of relationship, one specific record of the master table has more
than one corresponding records in the related transaction table
Many-to-Many relationship
In this type of relationship, there will be multiple records in the master table that
correspond to multiple records in the transaction table as well.
Example-shopkeeper may sell multiple products to multiple customers. So many-to-many
relationship exists between a product and a customer.
• Relations are set up between the tables to control data redundancy and inconsistency.
• A relationship can help prevent data redundancy.
• It helps prevent missing data by keeping deleted data from getting out of synch. This is called
referential integrity.
• Creating relationships between tables restricts the user from entering invalid data in the
referenced fields.
• Any updation in the master table is automatically reflected in the transaction tables.
•
Referential Integrity
According to the principle of referential integrity, no unmatched foreign key values should exist in
the database.
LibreOffice Base gives us following four options to choose from to maintain referential integrity in
such cases.
1. No action – This is the default option. This option states that a user should not be allowed to
update or delete any record in the master table if any related record exists in the transaction
table.
2. Update cascade – This option allows the user to delete or update the referenced field but along
with it all the related records in any of the transaction tables will also be deleted or updated.
3. Set NULL – This option assigns NULL value to all the related fields if the master record is deleted
or updated.
4. Set default – This option assigns any fixed default value to all the related fields if the master
record is deleted or updated.
Queries
Using a query, we can retrieve and display data from one or more tables in a database. This is done
by giving specific search criteria to the DBMS so that we are able to view the exact information that
we want. The information may be retrieved from a single table or from multiple tables.
LibreOffice Base allows us to create a query and even save it as an object in a database. This helps us
to run the query multiple times as and when required.
A query can be created in three ways. In this chapter you will learn the first two methods to create a
query.
Using a Wizard
In Design View
In SQL view
Creating a Query in Design View
1. Open Database: Launch the Sports Day database.
2. Access Queries: Click the Queries icon in the Objects Pane.
3. Start Design View: Select "Create Query in Design View…" to open the Query Design
Window.
4. Add Tables:
o Add the Events table by clicking it and pressing Add, or double-clicking it.
o Add the EventCategory table similarly.
5. Close Dialog: Close the Add Table or Query dialog box.
Forms
A form is an object of the database that has a user friendly interface where data can be entered and
seen in an attractive and easy-to-read format. For any database, it is the front end for data entry and
data modification. It displays the data in a layout design by us and not just in a simple row and
column format.
Overview of Forms
A form is an essential component of a database that provides a user-friendly interface for data entry
and modification. Unlike the standard row and column format of a table, forms present data in a
visually appealing and organized layout, making it easier for users to input and view information.
Key Components of a Form
• Field Controls: Each form contains various controls for data input, typically including:
o Label: Describes the data to be entered.
o Field Value Text Box: Where the user inputs the data.
Using Forms for Data Entry To enter new records:
1. Switch to Form View: Click the Design Mode button to toggle views.
2. Add New Record: Click the New Record button on the Records toolbar.
3. Input Data: Fill in the fields, then click Save Record to save the entry.
To delete records, navigate to the record and click the Delete button.
Reports
A report allows for customized presentation of data, making it visually appealing compared to
standard query outputs.
We have seen that the records that have been extracted using a query are displayed in a simple row
and column format. Instead, using a report we can present the retrieved data in an attractive and
customized manner.
If a report has to be generated from multiple tables, a query should be created first and then that
query can be used to generate the report.