DBMS Part 3
DBMS Part 3
SQL Commands
🔾 SQL can perform various tasks like create a table, add data to tables, drop
the table, modify the table, set permission for users.
There are five types of SQL commands: DDL, DML, DCL, TCL
🔾 DDL changes the structure of the table like creating a table, deleting a
table, altering a table, etc.
🔾 All the command of DDL are auto-committed that means it permanently
save all the changes in the database.
Here are some commands that come under DDL:
🔾 CREATE
🔾 ALTER
🔾 DROP
🔾 TRUNCATE
2. Data Manipulation Language
🔾 DML commands are used to modify the database. It is responsible for all
form of changes in the database.
🔾 The command of DML is not auto-committed that means it can't
permanently save all the changes in the database. They can be rollback.
Here are some commands that come under DML:
🔾 INSERT
🔾 UPDATE
🔾 DELETE
3. Data Control Language
DCL commands are used to grant and take back authority from any database user.
🔾 Grant
🔾 Revoke
Example
Example
TCL commands can only use with DML commands like INSERT, DELETE and UPDATE
only.
These operations are automatically committed in the database that's why they cannot
be used while creating tables or dropping them.
🔾 COMMIT
🔾 ROLLBACK
🔾 SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
1. COMMIT;
Example:
Syntax:
1. ROLLBACK;
Example:
Syntax:
1. SAVEPOINT SAVEPOINT_NAME;
BUILDING FORMS
1. Under Tables or queries, select Vacations as the table. Available fields lists the
fields for the Vacations table.
2. Click the right double arrow to move all of these fields to the Fields in the form
list. Click Next.
1. Under Tables or queries, select Vacations as the table. Available fields lists the
fields for the Vacations table.
2. Click the right double arrow to move all of these fields to the Fields in the form
list. Click Next.
This step is exactly the same as step 1. The only difference is that not all of the fields
will be used in the subform.
1. Select Fuel under Tables or queries.
2. Use the >> button to move all the fields to the right.
3. Click the FuelID field to highlight it.
4. Use the < button to move the FuelID to the left (Figure 23).
5. Click Next.
This step is for tables or queries for which no relationship has been defined. Since we
want to list all expenses by the day they occur in both the form and subform, we will
join the Date fields of these two tables (Figure 24).
1. Arrangement of the main form: Click Columnar - Labels on top. (The labels will
be placed above their field.
2. Arrangement of the subform: Click As Data Sheet. (The labels are column
headings and the field entries are in spreadsheet format.) Click Next.
Unless you have a need for any of these entries to be checked, accept the default
settings. Click Next.
Step 2
In relational databases a table can connect to another table and similarly a form can
contain a subform. Skip this step now because our database is flat and does not have
any relations.
Step 3
In this step we choose the form layout or arrangement. Click on all available options to
preview the result. For this form choose the Columnar - Labels Left layout.
Step 4
In this step we specify the data entry mode. You can create for example a form that the
user can only add records but not modify existing ones. In our example we will leave
the default options so that the form user has full rights.
Step 5
In this step you can quickly style the form using one of the predefined styles. Choose a
style (Bright Blue for example) and click Next.
Step 6
In this step we set the name of the form and how we want to proceed after creating the
form. Name the form Books or BooksForm and Choose Work with the form.
Using the Form
Navigating
When we open the Form it displays each record according to the chosen layout. Using
the navigation toolbar on the bottom we can navigate to each record of the table. The
toolbar on the bottom displays also the current record.
Creating a query
LibreOffice Base allow us to design, execute and store a query. You can create a query
with one of the following ways:
● Create a Query in Design View. This method allows us to design a query
from scratch. Use this method because it will help you undestand the comcept of
queries.
● Use Wizard to Create a Query. The wizard will guide you to create a query
from a selected table.
● Create a Query in SQL View. SQL stands for Structured Query
Language. SQL is the standard language for relational database management
systems. If you want to really dive into databases you should learn the SQL
language. This lesson however does not cover SQL.
To create a query select the Queries object from Database objects types and click on
the Create Query in Design View Task.
A query needs at least one table or another query where it can retrieve the data. Select
the Books table from the list to add it to the query.
Once you add the table close the Add Table or Query window. Now the Query Design
window appears. The upper part of this window displays the data sources where the
query retrieves data from. In the bottom part we set the query parameters.
Query parameters
Let’s now for example design a query that will ask the question: What books are
available in my library? Show me the title and author of these books. To design a query
we must specify it's parameters:
● Fields. The table fields to show in query results or use in the query's
criteria.
● Sorting. You can specify sorting for the results by one or more fields.
● Criteria. This is where we actually set the conditions for the query. We can
set multiple criteria in a query.
● Visible. If enabled the field will be visible in query results.
For our query we set the following query parameters:
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.
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".
Step 3
A report can group the results by one ore 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.
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.
When you finish the wizard the report will be created and opened. The report is 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.
1. Expand DDL, DML, DCL, TCL
2. Differentiate alter and update command
3. command used to view all records of a table