46
Database Ed Milne

Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Embed Size (px)

Citation preview

Page 1: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database

Ed Milne

Page 2: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Theme

An introduction to databases Using the Base component of LibreOffice

Page 3: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database

A database is a structured set of data held in a computer

Page 4: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

SQL

Structured Query Language (SQL) is a programming language used to create, maintain and extract data from databases It is an ISO standard

e.g. SELECT isbn, title, price, price * 0.14 AS sales_tax FROM book WHERE price > 100 ORDER BY title

Page 5: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Base

Base, a component of the LibreOffice suite is a front end to a databaseThe back end, the database engine, can be

A spreadsheet (Calc) HSQL – open source freeware embedded in base External sophisticated database engines such as PostgreSQL, MySQL and MariaDB

Page 6: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database Engines

The appropriate database engine depends on the performance of your computer and the amount of data in the database As a rough guide

Spreadsheets – up to 1,000 records HSQL – up to 50,000 records MYSQL etc. - over 50,000 records

Page 7: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database Engines

Using HSQL creates a database in a single fileUsing other engines creates two objects

The Base front end The DB engine containing the data

This can be useful when more than one person can be accessing the data at the same time In an organization, the engine can be on a server and a copy of the front end is on each employee's computer

Page 8: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database Engines

Sophisticated engines prevent two people from changing the same record at the same timeSeparate engines also make maintenance easier

Changes to the front end can be copied to each user e.g. New forms or reports

Changes to the engine only have to be made at a single location

Page 9: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database Engines

A separate front end and engine is also used on the web e.g. When you register at a web site, the form on the web page is the front end of a database

Page 10: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Tables

The data in a database is organized in tables which look much like a spreadsheet LibreOffice has a wizard for creating tables

Page 11: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Fields

A table consists of fields Each field is the equivalent of a column in a spreadsheet

Page 12: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Field Data Type

Each field can only accept a specific type of data cf. a spreadsheet where you can enter any type of data in any cell

Integer Big integer – up to 19 digits Integer – up to 10 digits Small integer – up to 5 digits Tiny integer – up to 3 digits

Page 13: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Field Data Type

Numbers Decimal – 10 digits

Fixed number of decimal places Float, Real, Double

17 digits e.g. 1.23E+017

Text Text – only uses the space required for the data Text (fix) Text (ignore case) Long text (memo) – up to 2,147,483,647 characters

Page 14: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Field Data Type

Date and Time Date Time – HH:MM:SS Timestamp – date and time

Boolean Yes/No

Page 15: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Field Data Type

Binary - up to 2,147,483,647 bytes Image Binary Binary (fix)

Other Up to 2,147,483,647 bytes

Page 16: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Indexes

Each table must have a primary index to uniquely identify each record cf. The row number in a spreadsheet The integer data type has an autonumber feature which automatically creates a unique number for the record

Page 17: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Relations

You can relate tables together by Adding a field for the primary index in another table to a table Linking these fields together

Page 18: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

One-to-Many Relationship

In the example shown, each media record can be linked to many books

Page 19: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Many-to-Many Relationship

A many-to-many relationship can be made using an intermediate table In the example shown,a book can have more than one subject and a subject can relate to many books

Page 20: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Views

You can create a View of a table which contains a subset of the fields in a table a set of fields from related tables

A view is a virtual table which can be used much like a table

Page 21: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Forms

Forms let you add or edit the information in a database LibreOffice has a wizard for creating forms from a table or view

Page 22: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Forms

The forms editor is the word processing component of LibreOffice After creation, you can modify the form

Page 23: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Filters

You can filter the data on a form so only records with certain values appear e.g. You can filter the data in a book form so that only records with the medium “Magazine” appear as you browse through the records

Page 24: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Datasheet Form

A datasheet form appears like a spreadsheet

Page 25: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Subforms

Subforms are forms within a form Typically a datasheet form within a field form

Page 26: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Form Controls

Check box Text box Numeric field Currency field Date field Time field Pattern field Spin button Push button

Option button Image button (icon) List box Combo box Label Image Scroll bar Frame Navigation bar

Page 27: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Check Box

A check box accepts a Boolean (Yes/No) value

Page 28: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Currency Control

Accepts a currency value The spin box control on the right increments or decrements the value by $1

Page 29: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Date and Time Controls

There are various ways to format the date and time The large down arrow displays a calendar The spin buttons change the value selected by the position of the cursor

E.g year, month or day

Page 30: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Dropdown Menus

Lets you select a value from a related table A list of constants embedded in the form

Page 31: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Dropdown Menus

A list box saves the index of the record in the related table in the primary recordA combo box saves the displayed text in the primary recordEither control can save the selected value in the form rather than the record

Page 32: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Buttons

Buttons can be used to execute a macro for the form set a value in the record

Page 34: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Macro Example

Page 35: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Executing Macros

You can execute a macro by Using the Run Macro option in the menus Assigning a shortcut key to the macro Linking the macro to an event for a form or control

Page 36: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Form Events

Page 37: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Push Button Events

Page 38: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Queries

Queries let you select, organize and manipulate data from the databaseQueries are used to select and organize the fields for

dropdown menus reports

Page 39: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Queries

Base provides a Graphical User Interface (GUI) for select queries to Select fields Determine which fields should be visible Select records with specific values in a field Sort the extracted data Apply functions like Count or Average to the fields

Page 40: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice
Page 41: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Queries

The GUI generates SQL code like

Page 42: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Queries

You can use other queries as well as tables as the data source i.e. You can created nested queries

In Base, you hand code other types of queries in SQL e.g. An Update query to make a mass change to the data

UPDATE "tblSubjectWork" SET "SubjectID" = '5' WHERE "SubjectID" = '7'

Page 43: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Reports

Base has a report generator to create reports from queries or tablesReports can be

Grouped Group headers and footers

Sorted Output to text documents or spreadsheets

Page 44: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Reports

Page 45: Database Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice LibreOffice

Database for Spreadsheets

Why use a spreadsheet as the back end of a database? You already have the data in a spreadsheet You want to use some features of a spreadsheet like charts and graphs A database allows strict data typing and limits

r.g. A value must be present and within a specific range Forms avoid horizontal scrolling Database reports