05_Database structure overview
05_Database structure overview
You’ve
been introduced to what a table is in a database, the basic structure of a table,
data types, what primary and foreign keys are and the roles they play in a table.
You also learned about table constraints.
The main objective of this reading is to cover the basic structure of a database. In
other words, you will learn more about tables, fields (or attributes), records, keys
and table relationships.
Table
A table contains all the fields, attributes and records for a type of entity. A database
will most probably contain more than one table.
Fields
Column headings are known as fields. Each field contains a different attribute. For
every table, a unit of data is entered into each field. It’s also known as a column
value. Each column has a data type. For example, the “agent_name” column has a
data type of text, and the “commission” column has a numeric data type.
Records
A record consists of a collection of data for each entity. It’s also known as a row in
the table.
Data types
To keep the data consistent from one record to the next, an appropriate data type
is assigned to each column. The data type of a column determines what type of
data can be stored in each column.
Data types are also a way of classifying data values or column values. Different
kinds of data values or column values require different amounts of memory to
store them. Different operations can be performed on those column values based
on their datatypes.
Numeric data types such as INT, TINYINT, BIGINT, FLOAT and REAL.
Date and time data types such as DATE, TIME and DATETIME.
Character and string data types such as CHAR and VARCHAR.
Binary data types such as BINARY and VARBINARY.
And miscellaneous data types such as:
Character Large Object (CLOB), for storing a large block of text in
some form of text encoding.
and Binary Large Object (BLOB), for storing a collection of binary
data such as images.
One-to-one relationships
One-to-many relationships
Many-to-many relationships
This is also known as cardinality of relationships. The logical database structure
which is represented using an ERD also depicts these relationships.
Let’s take the example of a database that contains two tables: student and
department. The student table has a primary key of “Stud_id”, which is also
present in the Department table as a foreign key. Therefore, the two tables are
related to each other via the “Stud_id” field.
In this reading, you learned more about the basic database structure including
tables, fields or attributes, records, keys and relationships between tables.