Rows repeat the columns structure of the table.
Datatypes
Restricts values to be of certain content and format.
- Simple Datatype
- Complex Datatype
- Specialized Datatypes
Simple Datatype
Strings
- Fixed Length: A fixed-length string will always store the specified length declare for the datatype. The value is padded with spaces even when the actual string value is less than the length of the datatype length.
- Variable-length: Allows storage into a datatype as the actual length of the string, as long as a maximum limit is not exceeded. VARCHAR(n) or TEXT(n) are common naming formats for variable-length strings. Strings are not padded.
Numbers
- Integers
- Fixed-length decimals: Digits on the right side of the decimal are restricted to a specified number of digits.
- Floating points: Decimal point “floats freely” anywhere within the number.
- Dates and times
Complex Datatypes
Complex datatypes encompass object datatypes.
Binary Objects: graphic objects
Reference pointers
Collection arrays
User-defined types
Specialized Datatypes
Types with inherent structure. Eg. XML documents, spatial data, and multimedia objects
Constrains and Validation
NOT NULL
Validation Check
Keys
Normalization
Normalization introduces consistency which is achieved by removing duplication in data among other factors.
Commercially speaking, primary objectives are usually to save space and organize data for usability and manageability, without sacrificing performance.All this is often a juggling act and commonly partially ironed out by trial and error
Normalization is an incremental process.
Benefits
Potential Normalization Hazards
Representing relationships in an ERD
A table is referred to an entity in an ERD.
An ERD displays tables and relationships between those tables.
Crows foot
Used to describe the "many" side of a one-to-many or many-to-many relationship.
One-to-One
Created to remove frequently NULL valued fields from a table.
One-to-One relationships are typical of 4th Normal Form transformations.
One-to-Many
One-to-many implies one entry to many entries between two tables.
Many-to-Many
A many-to-many relationship means that for every one record in one table there are many possible records in another related table and visa versa.
Zero, One, or Many
Relationships between tables can be zero, one or many.
Zero implies record does not have to exist in target table.
OneWithZero record can have to exist in target table.
One record must have to exist in target table.
Many
A rank SHOULD have a related row in Edition table.
i.e. every rank should be assigned to an existing book.
An Edition CAN or CANNOT have a related row in Rank table.
i.e every edition does not have to be ranked.
Identifying Relationship
The parent table primary key is included in the primary key of the child table.
Eg. the COAUTHOR table includes both the AUTHOR and PUBLICATION primary keys in the COAUTHOR primary key as a composite of the two parent table fields
The COAUTHOR table is dependent on the AUTHOR and PUBLICATION tables.
Non-Identifying Relationships
Child table includes the parent table primary key as a foreign key, but not as part of the child
table’s primary key.
Eg. a non-identifying relationship between the AUTHOR and PUBLICATION tables where the PUBLICATION table contains the AUTHOR_ID primary key field from the AUTHOR table.
Solid line implies dependent tables.
Dotted line implies independent tables.
Understanding Keys
an index in a relational database is a copy of a part of a table, perhaps structured in a specific format such as a BTree index
A key is both a key and an index. A key is an index because it copies fields in a table into a more efficient
searching structure.
Primary Keys
A primary key is used to uniquely identify a record in a table. Unique identification of each record is required because there is no other way to find a record without the possibility of finding more than one record.
Unique Keys
A unique key is created on a field containing only unique values through an entire table.
Integers are used as primary keys rather than the name of an author or a publication, and otherwise.
Integer value primary keys are known as surrogate keys because they substitute as primary keys for names.
If surrogate keys are used, it is common to see unique keys.
A primary key is also used to define relationships between tables.
Unique keys are not used to define relationships between tables.
Foreign Keys
NOT NULL
Validation Check
- a validation checking type of constraint restricts values in fields when a record is added or changed in a table.
- Eg. making sure a field allowing only M for Male or F for Female
Keys
- Key constraints include primary keys, foreign keys, and unique keys
Normalization
Normalization introduces consistency which is achieved by removing duplication in data among other factors.
Commercially speaking, primary objectives are usually to save space and organize data for usability and manageability, without sacrificing performance.All this is often a juggling act and commonly partially ironed out by trial and error
Normalization is an incremental process.
Benefits
- Physical space needed to store data is reduced
- Data becomes better organized
- Allows changes to small amounts of data to be made to one table at once
Potential Normalization Hazards
- Performance is always a problem with too much granularity caused by over application of normalization. Very demanding concurrency OLTP databases can be very adversely affected by too much granularity.
- Too much minimization of redundancy implies too much granularity and too many tables. Too many tables can lead to extremely huge SQL join queries.
Representing relationships in an ERD
A table is referred to an entity in an ERD.
An ERD displays tables and relationships between those tables.
Crows foot
Used to describe the "many" side of a one-to-many or many-to-many relationship.
One-to-One
Created to remove frequently NULL valued fields from a table.
One-to-One relationships are typical of 4th Normal Form transformations.
One-to-Many
One-to-many implies one entry to many entries between two tables.
Many-to-Many
A many-to-many relationship means that for every one record in one table there are many possible records in another related table and visa versa.
Zero, One, or Many
Relationships between tables can be zero, one or many.
Zero implies record does not have to exist in target table.
OneWithZero record can have to exist in target table.
One record must have to exist in target table.
Many
A rank SHOULD have a related row in Edition table.
i.e. every rank should be assigned to an existing book.
An Edition CAN or CANNOT have a related row in Rank table.
i.e every edition does not have to be ranked.
Identifying Relationship
The parent table primary key is included in the primary key of the child table.
Eg. the COAUTHOR table includes both the AUTHOR and PUBLICATION primary keys in the COAUTHOR primary key as a composite of the two parent table fields
The COAUTHOR table is dependent on the AUTHOR and PUBLICATION tables.
Non-Identifying Relationships
Child table includes the parent table primary key as a foreign key, but not as part of the child
table’s primary key.
Eg. a non-identifying relationship between the AUTHOR and PUBLICATION tables where the PUBLICATION table contains the AUTHOR_ID primary key field from the AUTHOR table.
Solid line implies dependent tables.
Dotted line implies independent tables.
Understanding Keys
an index in a relational database is a copy of a part of a table, perhaps structured in a specific format such as a BTree index
A key is both a key and an index. A key is an index because it copies fields in a table into a more efficient
searching structure.
Primary Keys
A primary key is used to uniquely identify a record in a table. Unique identification of each record is required because there is no other way to find a record without the possibility of finding more than one record.
Unique Keys
A unique key is created on a field containing only unique values through an entire table.
Integers are used as primary keys rather than the name of an author or a publication, and otherwise.
Integer value primary keys are known as surrogate keys because they substitute as primary keys for names.
If surrogate keys are used, it is common to see unique keys.
A primary key is also used to define relationships between tables.
Unique keys are not used to define relationships between tables.
Foreign Keys
Foreign keys are the copies of primary keys created into child tables to form the opposite side of the link in an inter-table relationship - establishing a relational database relation.
A foreign key defines the reference for each record in the child table, referencing back to the primary key in the parent table.
Understanding Indexes
Indexes are so important to performance and overall database usability.
An index is usually and preferably a copy of a very small section of table.
The act of creating an index physically copies one or more fields to be indexed into a separate area of disk other than that of the table
A foreign key defines the reference for each record in the child table, referencing back to the primary key in the parent table.
Understanding Indexes
Indexes are so important to performance and overall database usability.
An index is usually and preferably a copy of a very small section of table.
The act of creating an index physically copies one or more fields to be indexed into a separate area of disk other than that of the table
Avoid
Types of Indexes
BTree Index
Bitmap Index : binary representation of each record using 0's and 1's. Vulnerable to overflow over long periods of time.
ISAM Index : Indexed Sequential Access Method (ISAM) uses a simple structure with a list of record numbers.
Hash table : efficient for read access, but avoided subjected to any kind of data changes.
Index Organized Table
Overflow is bad for indexing because changes are placed outside of the optimized index structure.
Views
Essentially a query definition and does not contain any data.
Materialized Views
A materialized view materializes underlying physical data by making a physical copy of data from tables.
When a query is executed against a materialized view, the materialized view is physically accessed rather than the underlying tables.
- Creating too many indexes
- every change to a table updates every index attached to it as well as the table.
- Indexing too many fields
- index must be relatively much smaller than a table and should be created on a few fields from that table as is possible.
Types of Indexes
BTree Index
Bitmap Index : binary representation of each record using 0's and 1's. Vulnerable to overflow over long periods of time.
ISAM Index : Indexed Sequential Access Method (ISAM) uses a simple structure with a list of record numbers.
Hash table : efficient for read access, but avoided subjected to any kind of data changes.
Index Organized Table
Overflow is bad for indexing because changes are placed outside of the optimized index structure.
Views
Essentially a query definition and does not contain any data.
Materialized Views
A materialized view materializes underlying physical data by making a physical copy of data from tables.
When a query is executed against a materialized view, the materialized view is physically accessed rather than the underlying tables.









