Dbms Notes
Dbms Notes
DATA INFORMATION
Raw, unprocessed Processed, meaningful
Databases and DBMS
A database is a collection of logically related data items stored in an
organised manner. The information being stored in a database can be added,
modified, deleted or displayed according to the requirements of the user.
OR
A database is an organized collection of data that is stored and managed
electronically. It allows users to easily store, retrieve, and modify
information. Examples: Storing library records.
DBMS
The software that is used to create, update and retrieve data from a
database is known as database management system (DBMS).
It facilitates planning and maintenance of the database for the user.
For Example: MS Access, LibreOffice Base, Oracle, MySQL.
Advantages of DBMS:
Organised Storage – The data in the database is stored in an organised
manner, so the retrieval of required data is fast and accurate.
Minimal Data Redundancy – DBMS stores each piece of data only once,
reducing unnecessary duplication and inconsistencies.
Data Values
Data values are the raw data represented in numeric, character or
alphanumeric form. Examples of data values are ‘Saurabh Bhatt’, ‘21’
‘readers venue’, “Uttarakhand”, “03-01-2024”, etc.
Record or Row
A record holds the data values of all the fields for a single person or object
in a table. It is presented as rows within a table.
Super Key
A super key is a column or a combination of columns that can uniquely
identify each row in a table.
Candidate Key
A candidate key is a minimal super key, meaning that it is a set of
columns that uniquely identifies each row in a table and cannot be
reduced further without losing its uniqueness property.
Primary Key
A primary key is a column or a set of columns in a database table that
uniquely identifies each row. It ensures that no two rows have the same
value in the primary key column(s), and it cannot contain null values.
In a table we use more than one fields to identify a record, it is known as a
composite key.
Super key mei vo saare attribute aa
jayenge jo har ek row ko uniquely identify kar
sake ( jaise aadhar card + pancard + name +
SUPER KEY phone no. + address.. in sab ka combo).
CANDIDATE
KEY
Ab super key mein extra attributes bhi hai
unko hata ke dekhe toh shirf aadhar card ya
pan card bhi toh ek insaan identify kar skta
Primary Key
hai baaki attribute ki kya jarurat.
A table can have multiple candidate keys, but only one primary key.
Alternate Keys
It is a candidate key that is not chosen as the primary key, but can still be
used to uniquely identify each row.
Foreign Key
A foreign key is a field (or a combination of fields) in one table that refers
to the primary key in another table. It establishes a relationship between
two tables, ensuring data integrity by linking the records.
Objects of RDBMS
In DBMS, objects are the structures or components used to store and
manage data. They help organize, retrieve, and manipulate data efficiently.
For example, names are stored in the form of text, age in numbers, fees
in decimal numbers, date of birth in date format and so on.
Binary
The Binary data type used to store digitized images and sounds that
comes as long string of zeros and ones.
Saving a Table
To save the table click on the save button or follow menu option File >
Save As. Enter the name of table in the dialog box and click on OK button.
Shortcut Key: Press Ctrl + S to save the table.
Entering Data in a Table
Step 1: Double-click or right-click and select "Open" on the desired table.
Step 2: The table opens in datasheet view with field names in the top row.
Step 3: Place the cursor in the first blank field of the second row and type data.
Step 4: Use the Tab key to move to the next field in the row.
Step 5: After filling all fields, the cursor moves to the next record (row).
Step 6: Use the horizontal scroll bar to access hidden fields if there are many.
Step 7: Continue adding records, and verify data before saving.
To delete a record:
1. Select the record.
2. Use one of the following methods:
Press the Del key.
Select Delete Record from the Edit menu.
Right-click the record and choose Delete Rows.
3. A confirmation box will appear:
Click Yes to delete the record. OR Click No to cancel.
Sorting Data in a Table
Sorting arranges table records in ascending or descending order based on a
selected field.
Steps to Sort:
1. Open the table and select the field to sort.
2. From the toolbar:
Click Sort Ascending (A-Z icon) for ascending order.
Click Sort Descending (Z-A icon) for descending order.
The table will sort accordingly.
3. For Multi-Field Sorting:
Click the Sort icon to open the Sort Order dialog.
Select fields, choose ascending or descending order, and click OK to apply.
MASTER Record
Transaction table
PRIMARY KEY
Transaction
Record
Foreign Key
Types of Relationships
One specific record of the master table has more than one
One-to-Many corresponding records in the related transaction table.
Types of Relationships
Referenced
table
Foreign Key
Primary Key
Event
Referencing
table
Referential Integrity
According to the principle of referential integrity, no unmatched foreign key
values should exist in the database. If a record is removed from the parent table,
the corresponding records in the child table must also be updated or deleted.
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.
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.
This option assigns NULL value to all the related fields if the master
Set NULL
record is deleted or updated.
This option assigns any fixed default value to all the related fields
Set default
if the master record is deleted or updated.
To set the relationship properties double click on the relation line joining
the two tables. A Relations dialog box will open.
By default the radio button with No action option will be selected.
Choose any of the desired option and click OK to set the referential integrity
between the two tables.
Queries
Using a query, we can retrieve and display data from one or more tables in a
database.
Using a query, we can specify the fields that we want to display and also the
criterion based on which the records to be filtered.
The result of the query is displayed in tabular form.
Creating a Query
A query can be created in three ways.
1. Using a Wizard
2. In Design View
3. In SQL view
Creating a Query Using a Wizard
To execute query, we wil use two tables- Events and EventCategory.
We will create a query that will display the Event Name and Winner for each
event with CategoryID as C001.
Step 1 In the Database Design window, click on Queries button present in the
Database Pane on the left.
Step 2 In the Tasks Area, click on Use Wizard to Create Query Option.
The Query Wizard window will appear. It contains the Steps Pane on the
left and the Query Details Area on the right.
Step 3 The first step of the wizard is to select fields from the respective tables.
Select Events table from the Tables list box.
Step 4 Select Event Name, Winner and CategoryID field from the list box and click
the right arrow (>) button to move all fields to Fields in the Query box.
Step 5 Clicking on the Next button will display the screen to select the sorting
order. The result of the query can be displayed in ascending or
descending order of any particular field of the table.
If we do not want any particular order, we can directly click on Next.
Step 6 The next step is to set the search conditions or the criteria on the basis of
which records will be filtered from the table.
Step 7 Select CategoryID field from Fields drop down list, is equal to from
Condition drop down list and type the value as C001. Click Next.
[Three search conditions can be given at the most in the wizard.]
Step 8 If we want to display a different name instead of the original column
name, we can set it here.
Step 9 The last step of the Query wizard displays the entire overview of the
query. It displays the overall structure of the query.
Name of the Query - By default, the name of the query is Query_Events
by default. If desired, type the new name in the text box.
The action to be performed after the wizard finishes- By default
Display Query option will be selected.
Click and select the Modify Query radio button if the query has to be
edited in the Design view.
Step 10 Click on Finish button. The records with CategoryID as C001 will be
displayed on the screen.
Creating a Query in Design View
We will create a query to display records of Athletics category. For this query,
records have to be filtered from both Events and EventCategory tables.
Step 1 Click Queries icon on the Database Pane in the Database Window.
Step 2 Click Create Query in Design View… icon in the Tasks Pane. The Query
Design Window appears. In the middle of the window the Add Table or
Query dialog box is displayed.
Step 3 Click on the Event table to be used in the query and then click on Add
button. Alternatively double click on the Events table. The Event table
will be added to the Tables Pane.
Step 4 Similarly add the EventCategory table.
Step 5 Click Close button in the Add Table or Query dialog box to close it.
Step 6 Next step is to select the fields. For our query we want to display Event
Name and Winner from the Events table and Category Name from the
EventCategory table.
So in the list box of Events table, double click on EventName and Winner
field, and they will be displayed in the Design grid.
Note:-Observe that the Visible Check Box is selected by default. This means
that all these three fields will be visible when you run the query.
If you do not want the data values for the particular field to be
displayed, click to deselect the respective check box.
Step 7 Next we will set Alias names for the columns that will be displayed in the
output. For example, to change Winner -> Winner Name, type Winner
Name in the Alias text box under Winner column.
Step 8 To sort the records in either ascending or descending order of a
particular field, use the Sort row given in the grid.
Step 9 To display records of Athletics category only, type ‘Athletics’ in the
Criterion row under the Category Name column.
Step 10 Once the query is designed, click Run Query ( ) button on the toolbar or
press F5 key. The query result will be displayed in the Tables Pane area.
Step 11 Click on Save button to save the query. The Save As dialog box will be
displayed. By default, the Query Name as Query1 will be displayed. Type
a different name if required. Click on OK button to save the query.
Editing a Query
Step 1 Right click on the Query Name in the Objects Area of the Database
window.
Step 2 Select Edit option from the popup menu.
Step 3 Make the desired changes and click the Save button.
Note:- We can use the Criterion row to apply multiple conditions. We can apply
all relational operators like <, >, <=, >=, != and = for all conditions that can
be given in Criterion row.
For example, if you want to see only those records where points scored
are more than 10, then add Points field to the grid and then set the
Criterion for it as >10.
Working with Numerical Data
Till now, we have been displaying data from tables in the query.
We can even use certain mathematical functions to find the count, sum,
minimum, maximum or average of data values.
Step 1 Click Create Query in Design View. Add Events and EventsCategory
tables.
Step 2 Add Category Name field from EventCategory table and Points field
from Events table.
Step 3 Under the Category Name field, in the Function row, select Group option
from the drop down list.
Step 4 Similarly, under the Points column, select the Average function from the
drop down list.
Step 5 Press F5 to run the query. The query result depicting average points in
all the categories will be displayed.
Forms And Reports
Both are considered as objects of the database and are present in the
Database Pane of the LibreOffice Base User Interface.
Step 4: Select Area tab and choose the desired color from the palette
Step 5: Click on OK button. The selected color will be applied on the form
Modifying a Form
Editing the labels
Step 1: Place the mouse pointer over the label to change it.
Step 2: Press Ctrl + Click to select the label, displaying position boxes around it.
Step 3: Right click on the selected label > Control Properties
Step 4:The Properties: Label Field dialog box appears, allowing you to update
the label caption and modify properties like width, height, alignment,
font style, and size.
Step 5: After making changes, close the Properties dialog box by clicking ‘X’
button. The changes will apply to the selected text.
Modifying a Form
Moving a control :
Click on it to select both the label and text box with position handlers.
Step 3: In the Properties: Date Field dialog box, scroll down to the Date Format
property. The default format is Standard (short).
Step 4: Click to open the list box and select Standard (long) format.
Step 5: Scroll to the DropDown property and change its value from No to Yes.
Step 6: Close the dialog box. The date text box will change to a list box with an
arrow on the right.
Forms Controls Toolbar
Step 1: Click the Label tool on the Form Controls tool box
Step 2: On the form, click and drag to create a label field box.
Step 3: Double click on box to open the Properties: Label Field dialog box.
Step 5: Click the Font button under Font property to open the Character dialog
box. Select the desired font, style, and size, then click OK.
Step 6: Close the Properties: Label Field dialog box to display the formatted title on the form.
Forms Controls Toolbar
Click Design Mode on the Forms Controls toolbar to switch to Form View.
The Form View window opens, showing the first record.
To add a new record, click New Record icon on the Records toolbar.
A blank form appears with the cursor in the first text box .
Enter data and click Save Record icon on the Records toolbar to store it.
To delete a record, navigate to it using the record number box or
navigation buttons, then click Delete on the Records toolbar.
Toggle between Design View and Form View using the Design Mode button.
Reports
A report in a DBMS presents retrieved data in an organized and customized
format, enhancing visualization compared to a simple row-and-column
query display.
Creating a report
Step 1: In LibreOffice Base, click the Reports icon in the Database Pane.
Step 2: From the Tasks Pane, click Use Wizard to Create Report option.
Step 3: The Report Wizard opens along with the Report Builder window and the
Add Field dialog box.
Step 4: In the report wizard, select the table and then fields for the report.
Step 5: The Available Fields list displays all fields from the table. Click > button
to add them to the Fields in Report list.
Step 6: Click Next to label fields. Column headers are used as default labels,
but you can replace them with more descriptive names if needed.
Step 7: Click Next to proceed. This step allows grouping data by a field, but
since no grouping is needed, click Next again.
Step 8: Set Sort Options by selecting a field and choosing ascending or
descending order for data arrangement in the report.
Step 9: Click on the Next button to move on to the next step in which the layout
of the report will be selected.
Step 10: Select a layout and set the header & footer layout . Choose the orientation
as Landscape or Portrait, keeping Landscape selected by default.
Step 11: Click Next , Enter the report name . By default, the report is Dynamic,
updating automatically with table changes. To prevent updates,
select Static. Choose to modify or create the report, keeping the
default setting to create it.
Step 12: Click on Finish button to display the report.
Inserting other controls in the report