44
Database Design Strategies Database Design Strategies Alinari

Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Database Design StrategiesDatabase Design Strategies

Alinari

Page 2: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relational Databases

◆ A relational database separates data by subject into different tables that are then related by common fields

◆ A relational database can ensure that your data is easily maintained over time

Page 3: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relational Databases

✔Eliminates duplicate information✔Eases data entry and maintenance✔Eases data viewing and querying

Benefits of a Relational Database

Page 4: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Tables

◆ A table is the primary structure in a relational database, composed of fields and records

Page 5: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Tables

✔Table Name✔Table Category

– Data– Reference– Cross-Reference

✔Table Description

Important Elements of a Table

Page 6: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Tables

Tables that contain data about more than one subject

Tables that do not have a primary key

Primary Pitfalls to Avoid in Tables

Page 7: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

◆ A field is an attribute, or characteristic, of the subject of the table

Page 8: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

General Elements✔Field Name✔Table Name✔Field Description

Important Elements of a Field

Page 9: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

Table Elements✔Type of Key

– None, Primary, Foreign, Alternate

✔Unique Value✔Required Value✔Data Type

– Boolean, Alphanumeric, Numeric, DateTime, Counter– Valid Characters, Length, Decimal Places

Important Elements of a Field

Page 10: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

Data Entry Elements✔Field Label✔Values Entered By

– User, System

✔ Input Mask✔Display Format✔Default Value

Important Elements of a Field

Page 11: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

Data Validation/Domain Elements✔Range of Allowed Values✔Set of Allowed Values✔Validation Rule

Important Elements of a Field

Page 12: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

Query Elements✔Comparisons Allowed

– =, !=, >, >=, <, <=

✔Operations Allowed– Addition, Subtraction, Multiplication, Division

Important Elements of a Field

Page 13: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Fields

Fields containing multiple valuesRepeating data valuesFields containing calculated values

Primary Pitfalls to Avoid in Fields

Page 14: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relationships

◆ A relationship is a connection between two tables

◆ A relationship can eliminate duplicate or redundant data

Page 15: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relationships

✔Parent Table Name✔Child Table Name✔Relationship Type

– One-to-One (1:1)– One-to-Many (1:M)– Many-to-Many (M:M)

Important Elements of a Relationship

Page 16: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relationships

Not using relationships; or creating all fields in a single table that should be broken into two or more related tables

Primary Pitfalls to Avoid in Relationships

Page 17: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Relationships

Finding one-to-many relationships in your data should signify to you that a relational database is the best choice for your data!In this case, a flat file will not accurately model your data.

Relational Data “Red Flag”

Page 18: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

◆ Normalization is the process of converting data from a flat file format into a proper relational database

◆ Normalization separates the fields from a large table into multiple, smaller, related tables by removing all unnecessary or duplicate fields

◆ Normalization ensures that each table represents only one subject

Page 19: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

All data is stored in a single tableA single record contains information on more

than one subjectA single record contains repeating fieldsMultiple records contain the same values for a

group of fields

Signs of a Non-Normalized Table

Page 20: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

◆ 1NF: Eliminate repeating groups

Page 21: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

✔Each table is identified with a primary key✔No table contains repeating values

Signs of a Database in First Normal Form

Page 22: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

◆ 1NF: Eliminate repeating groups◆ 2NF: Eliminate redundant data

Page 23: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

✔No table contains redundant data; or groups of repeated values for multiple records

Signs of a Database in Second Normal Form

Page 24: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

◆ 1NF: Eliminate repeating groups◆ 2NF: Eliminate redundant data◆ 3NF: Eliminate columns not dependent on the

key

Page 25: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Normalization

✔Each table contains only fields that are dependent on the primary key; or directly related to the subject of the table

Signs of a Database in Third Normal Form

Page 26: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Database Design Standards

◆ Database standards allow for the development of consistent, well-designed databases– Important for sharing data among multiple users– Important for merging data at a regional level

◆ A user familiar with the standards can open any database developed with those standards and have a good understanding of the tables

Page 27: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Database Design Standards

✔You can easily modify and maintain the structure of your tables and fields

✔You can easily modify the data in your database✔You can easily retrieve and compare information

from your database✔You can easily develop data entry windows and

more robust applications for your database

Advantages of a Well-Designed Database

Page 28: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

✔has a unique descriptive name that is meaningful to the entire organization

✔accurately, clearly, and unambiguously identifies the table subject or field characteristic

✔has the minimum number of words necessary to convey the table subject or field meaning

✔does not contain unknown acronyms or abbreviations

A good table or field name...

Page 29: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

✔does not contains words that describe the physical characteristics, such as “file”, “record”, “data”, or “table”

✔does not identify more than one table subject or field characteristic

✔uses the singular form of the name

A good table or field name...

Page 30: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

Sample EventsSample IDsite id

✔sample_event✔sample_id✔site_id

Poor Choices Better Choices

Avoid Spaces

Page 31: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

Site/Locationsphone #%MossCoverRain?project$

✔site_location✔phone_num✔moss_cover_percent✔ is_raining✔project_cost

Poor Choices Better Choices

Avoid Special Characters

Page 32: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

birddetectionsCLOUDCOVERdwarfsaplingheight

✔bird_detection✔cloud_cover✔dwarf_sapling_height_ft

Poor Choices Better Choices

Separate Words

Page 33: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

DIGITAL_PHOTOSampleStartTimeWindSpeed

✔digital_photo✔sample_start_time✔wind_speed_mph

Poor Choices Better Choices

Use Consistent Case

Page 34: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

life_stagesNumBirdsObserver_Names

✔ life_stage✔bird_count✔observer_name

Poor Choices Better Choices

Singularize Names

Page 35: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

smptrnidWtrCodcol_for_cur

✔sample_transect_id✔water_code✔ is_collected_for_curation

Poor Choices Better Choices

Avoid Unknown Abbreviations

Page 36: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

water_quality_evaluation_code

DescriptionOfGeomorphicDisturbance

smptrnid

✔h2o_quality_eval_code✔geomorphic_disturb_desc✔sample_transect_id

Poor Choices Better Choices

Limit Length

Page 37: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

AmphibianSizetree_sizeTree_Name

✔amphibian_length_in✔ tree_height_m✔ tree_species_name -or-

tree_common_name

Poor Choices Better Choices

Use Specific Names

Page 38: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

full_nameCityStateZipobservers_initials

✔ first_name, last_name✔city_name, state_code,

zip_code✔observer_initials

Poor Choices Better Choices

Ensure Single Values

Page 39: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

total_line_item_costplot_area_m2event_duration_time

✔ item_qty, unit_cost✔plot_width_m,

plot_height_m✔event_start_time,

event_end_time

Poor Choices Better Choices

Avoid Calculations

Page 40: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming Standards

avgcountcurrencydatedescexists

Poor Choices

Avoid Reserved Words

groupindexkeymaxmemomin

namenumberorderpercentpropertysection

setsumtimetypevalueyear

Page 41: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming a Table

◆ Data table prefix name with tbl_◆ Reference table prefix name with ref_◆ Cross-reference table prefix name with xref_

What category does this table fall into?

What noun or short phrase summarizes the contents of this table?◆ This should adhere to the naming standards

Page 42: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming a Table

✔ tbl_site✔ tbl_sample_event✔ ref_park✔ ref_precipitation✔xref_sample_observer

Good Choices

Page 43: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Naming a Field

What noun or short phrase summarizes the contents of this field?◆ This should adhere to the naming standards

What category describes the type of data in this field?

What unit of measure, if any, is required for this field?

Page 44: Database Desiggnn Strategegies · Naming a Table Data table prefix name with tbl_ Reference table prefix name with ref_ Cross-reference table prefix name with xref_ What category

Design Strategies Recap

◆ Standards add value to your data◆ Develop naming standards

– Formatting conventions– Naming conventions