|
Designing the Database "On Paper"
From NeoWiki
Revision as of 13:23, 6 October 2007 (edit) Lorinda (Talk | contribs) (→Planning Tables and Fields - Remove Convenience Table section, add more info on tables and fields.) ← Previous diff |
Current revision (21:53, 12 December 2008) (edit) (undo) Lorinda (Talk | contribs) (add link to Sumit database design course, both in External links and introductory paragraph) |
||
(22 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
{{TBBA Header}} | {{TBBA Header}} | ||
- | Before actually creating a new Database document in NeoOffice, it is important to think through what sorts of data you will be storing and how you need to access it. Planning out your database on paper ahead of time will save you hours of frustration and restructuring later. | + | Before actually creating a new Database document in NeoOffice, it is important to think through what sorts of data you will be storing and how you need to access it. Planning out your database on paper ahead of time will save you hours of frustration and restructuring later. [What follows is a rather informal description by someone who has been essentially self-taught when it comes to database design. For a discussion of database design that covers the formal theory as well as offering an example, see [http://www.sum-it.nl/cursus/dbdesign/english/index.php3 the Sum-it Database Design Course]] |
==First Questions== | ==First Questions== | ||
Line 9: | Line 9: | ||
*What do I want to do with the data? What kind of reports do I want to be able generate? | *What do I want to do with the data? What kind of reports do I want to be able generate? | ||
- | :: For the birder's journal, | + | :: For the birder's journal, we want to be able to: |
:::See the data for particular field trips. (e.g. what birds did I see at Skokie Lagoons on April 1, 2007?) | :::See the data for particular field trips. (e.g. what birds did I see at Skokie Lagoons on April 1, 2007?) | ||
:::Produce a list of all the birds seen at a particular location over time. (e.g. all the birds I've ever seen at Skokie Lagoons) | :::Produce a list of all the birds seen at a particular location over time. (e.g. all the birds I've ever seen at Skokie Lagoons) | ||
Line 16: | Line 16: | ||
*How should the data be grouped | *How should the data be grouped | ||
- | :Simple linear databases (like the database in ClarisWorks/Appleworks, for example) only allowed you to work with one table or group of data in a data base. This limited what kind of data | + | :Simple linear databases (like the database in ClarisWorks/Appleworks, for example) only allowed you to work with one table or group of data in a data base. This limited what kind of data you could store and how it could relate. Relational databases like Base (and File Maker Pro and Helix RADE for Classic), allow you to work with multiple tables of relatively independent data that can relate to each other in a variety of ways. |
- | + | :Figuring out how to group your data, or what tables you need, is an essential. Think carefully about what data is closely tied together, and what data needs to be independent of other groups (or tables) of data. In a simple database to catalog music, for example, you might want to three groups: Albums (Name, date, etc.), Songs, and Composers. These should be separate because an Album contains more than one song, and Composers(or Artists) produce more than one Album. | |
:For the birders journal, the most natural groupings are: | :For the birders journal, the most natural groupings are: | ||
Line 25: | Line 25: | ||
::Locations (one record for each location) | ::Locations (one record for each location) | ||
::Sightings (one record for each bird seen) | ::Sightings (one record for each bird seen) | ||
- | |||
==Planning Tables and Fields== | ==Planning Tables and Fields== | ||
- | Once you have given thought to these questions, you are ready to beginning planning what tables and fields you need. | + | Once you have given thought to these questions, you are ready to beginning planning what tables and fields you need. |
+ | |||
+ | ===Guidelines for Field and Table names=== | ||
*Field names must begin with a letter and must only contain letters, numbers, and underscores. No spaces or other characters. | *Field names must begin with a letter and must only contain letters, numbers, and underscores. No spaces or other characters. | ||
*Table names can contain spaces, but the standard is to use underscores instead. | *Table names can contain spaces, but the standard is to use underscores instead. | ||
- | *Field names should be easily understandable by anyone | + | *Field names should be easily understandable by anyone using the database |
- | *Field names should be unique across the whole database. You '''can''' have a field called "ID" in each table, and the database will work (because Neo keeps track of what table it comes from), but it is more confusing for the User. It is better to name these fields | + | *Field names should be unique across the whole database. You '''can''' have a field called "ID" in each table, and the database will work (because Neo keeps track of what table it comes from), but it is more confusing for the User. It is better to name these fields AOU_ID, Sightings_ID, etc., so it is clear in the field name what table it relates to. |
- | + | <br>'''Note:''' For more guidelines for creating good tables, see the book ''SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL'' (2nd Edition) by John L. Viescas and Michael J. Hernandez and/or the Wikipedia article on [http://en.wikipedia.org/wiki/Database_Normalization Database Normalization]. (The book is easier reading than the Wikipedia article). | |
- | + | <br> | |
- | + | '''Note:''' Field naming in this tutorial is not entirely consistent with these guidelines. I began the birding database project before I was aware of them. I have tried to make corrections where possible, but I have not been entirely consistent. In most cases I have replaced spaces with underscores, but in a few cases (e.g. EnglishName) I simply deleted the space. If you encounter discrepancies in particular field names, please send a pm to [[User:Lorinda|Lorinda]] at [http://trinity.neooffice.org trinity] or, if you have editing privileges on this wiki, leave a note on her [[User talk:Lorinda|talk page]]. | |
- | + | ||
- | + | ===Making a Table and Field List=== | |
- | + | Now make a list of the tables you need. | |
- | + | :*Include the names of all the fields that need to be included in each table. | |
- | + | :*Make sure to include a "Primary Key" in each table. Primary Keys are fields whose entry is unique for each record. Most often, it is best for the Primary Key to be an number (interger) that Base sets itself. But sometimes it makes sense for the primary key to be something else. | |
+ | :*For each field, decide what type of field it needs to be (text, date, number, yes/no, etc.). | ||
+ | :*Decide how the table will relate to each other. What are the common fields? | ||
+ | :*If certain fields will usually (but not always) have a certain value (e.g. State, Country, etc.) make note of a default value to be entered when defining fields and creating the table. | ||
+ | :*Double check to make sure you have followed the guidelines for naming conventions discussed above | ||
+ | |||
+ | ===Finished Planning List for the Birding Database=== | ||
+ | Unless otherwise noted, field type is text. | ||
Birds Table (named AOU_Birdlist) | Birds Table (named AOU_Birdlist) | ||
:I used the AOU list available as an xls file from [http://www.aou.org/checklist/index.php3 the American Ornithologists' Union's website] Fields are determined by the column headers. | :I used the AOU list available as an xls file from [http://www.aou.org/checklist/index.php3 the American Ornithologists' Union's website] Fields are determined by the column headers. | ||
- | :I added an | + | :I added an AOU_ID column/Field to use as the primary key. (integer field type) |
- | (For more information on using this spreadsheet as the basis of a table, see [[Creating a Table From a Spreadsheet]].) | + | :(For more information on using this spreadsheet as the basis of a table, see [[Creating a Table From a Spreadsheet]].) |
- | + | Field_Trips Table | |
- | : | + | :FieldTrip_ID (primary key; integer field type, autovalue) |
- | :Date | + | :Date (date field type) |
- | :Start_Time | + | :Start_Time (time field type) |
- | :End_Time | + | :End_Time (time field type) |
:Field_Trip_Location (relates to Locations table) | :Field_Trip_Location (relates to Locations table) | ||
:Weather | :Weather | ||
Line 63: | Line 70: | ||
Sightings Table | Sightings Table | ||
- | : | + | :Sightings_ID (primary key; integer field type, autovalue) |
- | : | + | :Bird_Name (relates to Birds Table) |
- | :Sightings_Field_Trip_ID (relates to | + | :Sightings_Field_Trip_ID (relates to Field_Trips Table; integer field type) |
- | :Male (Yes/No) | + | :Male (Yes/No field type) |
- | :Female (Yes/No) | + | :Female (Yes/No field type) |
- | :Juvenile (Yes/No) | + | :Juvenile (Yes/No field type) |
- | :Voice (Yes/No) - bird identified by its voice | + | :Voice (Yes/No field type) - bird identified by its voice |
- | :Sight (Yes/No) - bird identified by sight. | + | :Sight (Yes/No field type) - bird identified by sight. |
:Comments (bird behavior, where cited, etc.) | :Comments (bird behavior, where cited, etc.) | ||
- | (Note: if tracking sightings for a family of birders, add two yes/no fields for each family member, one for voice and one for sight. e.g. JaneVoice, JaneSight, | + | :('''Note:''' if tracking sightings for a family of birders, add two yes/no fields for each family member, one for voice and one for sight. e.g. JaneVoice, JaneSight, JohnVoice, JohnSight. I also discovered that it was handy to have a GuestVoice and a GuestSight field. That way if I am birding with a group I can add sightings by other members of the group. This is helpful for tracking information about birds seen at particular locations, for example.) |
Locations Table | Locations Table | ||
- | : | + | :Location_ID (primary key; integer field type, autovalue) |
+ | :Location_Name (relates to Field_Trips table) | ||
+ | :City | ||
:County | :County | ||
- | : | + | :StateOrProvince (default value to your state) |
- | :Country | + | :Country (default value to your country) |
- | : | + | :Terrain_Type |
- | : | + | :Water_Type |
- | + | :Comments (memo(longvarchar)) | |
- | ''Note | + | <br><br> |
+ | '''Note''' There is no direct relationship between the Field_Trips Table and the Birds Table nor is there a direct relationship between the Locations Table and the Sightings Table or the Locations Table and Birds Table. But these tables can be related together in Queries, as long as the Query includes third table that does relate to the 'unrelated' tables. For example, while the Sightings Table and the Locations Table do not have a direct connection, the Field Trips table can act as an intermediary, as it relates to both of these tables. | ||
<!-- Removed because I learned a better way to do this | <!-- Removed because I learned a better way to do this | ||
Line 116: | Line 126: | ||
==Related External Links== | ==Related External Links== | ||
+ | * [http://www.sum-it.nl/cursus/dbdesign/english/index.php3 the Sum-it Database Design Course] | ||
* [http://www.oooforum.org/forum/viewtopic.phtml?p=108553#108553 Books on database design] from OOoForum.org<br> | * [http://www.oooforum.org/forum/viewtopic.phtml?p=108553#108553 Books on database design] from OOoForum.org<br> | ||
* [http://www.oooforum.org/forum/viewtopic.phtml?t=60484 OpenOffice.org Forum discussion on planning a database]<br> | * [http://www.oooforum.org/forum/viewtopic.phtml?t=60484 OpenOffice.org Forum discussion on planning a database]<br> |
Current revision
Before actually creating a new Database document in NeoOffice, it is important to think through what sorts of data you will be storing and how you need to access it. Planning out your database on paper ahead of time will save you hours of frustration and restructuring later. [What follows is a rather informal description by someone who has been essentially self-taught when it comes to database design. For a discussion of database design that covers the formal theory as well as offering an example, see the Sum-it Database Design Course]
Contents |
First Questions
Begin planning by asking yourself these questions:
- What kind of data do I need to store?
- For the birder's journal, the data we need includes birds, dates of sightings, locations, information about field trips, etc.
- What do I want to do with the data? What kind of reports do I want to be able generate?
- For the birder's journal, we want to be able to:
- See the data for particular field trips. (e.g. what birds did I see at Skokie Lagoons on April 1, 2007?)
- Produce a list of all the birds seen at a particular location over time. (e.g. all the birds I've ever seen at Skokie Lagoons)
- Produce a life list, a list of all the birds I've seen over my lifetime (with each species of bird listed only once)
- Perhaps even filter by location and weather conditions.
- For the birder's journal, we want to be able to:
- How should the data be grouped
- Simple linear databases (like the database in ClarisWorks/Appleworks, for example) only allowed you to work with one table or group of data in a data base. This limited what kind of data you could store and how it could relate. Relational databases like Base (and File Maker Pro and Helix RADE for Classic), allow you to work with multiple tables of relatively independent data that can relate to each other in a variety of ways.
- Figuring out how to group your data, or what tables you need, is an essential. Think carefully about what data is closely tied together, and what data needs to be independent of other groups (or tables) of data. In a simple database to catalog music, for example, you might want to three groups: Albums (Name, date, etc.), Songs, and Composers. These should be separate because an Album contains more than one song, and Composers(or Artists) produce more than one Album.
- For the birders journal, the most natural groupings are:
- Birds (one record for each species)
- Field Trips (one record for each trip)
- Locations (one record for each location)
- Sightings (one record for each bird seen)
Planning Tables and Fields
Once you have given thought to these questions, you are ready to beginning planning what tables and fields you need.
Guidelines for Field and Table names
- Field names must begin with a letter and must only contain letters, numbers, and underscores. No spaces or other characters.
- Table names can contain spaces, but the standard is to use underscores instead.
- Field names should be easily understandable by anyone using the database
- Field names should be unique across the whole database. You can have a field called "ID" in each table, and the database will work (because Neo keeps track of what table it comes from), but it is more confusing for the User. It is better to name these fields AOU_ID, Sightings_ID, etc., so it is clear in the field name what table it relates to.
Note: For more guidelines for creating good tables, see the book SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL (2nd Edition) by John L. Viescas and Michael J. Hernandez and/or the Wikipedia article on Database Normalization. (The book is easier reading than the Wikipedia article).
Note: Field naming in this tutorial is not entirely consistent with these guidelines. I began the birding database project before I was aware of them. I have tried to make corrections where possible, but I have not been entirely consistent. In most cases I have replaced spaces with underscores, but in a few cases (e.g. EnglishName) I simply deleted the space. If you encounter discrepancies in particular field names, please send a pm to Lorinda at trinity or, if you have editing privileges on this wiki, leave a note on her talk page.
Making a Table and Field List
Now make a list of the tables you need.
- Include the names of all the fields that need to be included in each table.
- Make sure to include a "Primary Key" in each table. Primary Keys are fields whose entry is unique for each record. Most often, it is best for the Primary Key to be an number (interger) that Base sets itself. But sometimes it makes sense for the primary key to be something else.
- For each field, decide what type of field it needs to be (text, date, number, yes/no, etc.).
- Decide how the table will relate to each other. What are the common fields?
- If certain fields will usually (but not always) have a certain value (e.g. State, Country, etc.) make note of a default value to be entered when defining fields and creating the table.
- Double check to make sure you have followed the guidelines for naming conventions discussed above
Finished Planning List for the Birding Database
Unless otherwise noted, field type is text.
Birds Table (named AOU_Birdlist)
- I used the AOU list available as an xls file from the American Ornithologists' Union's website Fields are determined by the column headers.
- I added an AOU_ID column/Field to use as the primary key. (integer field type)
- (For more information on using this spreadsheet as the basis of a table, see Creating a Table From a Spreadsheet.)
Field_Trips Table
- FieldTrip_ID (primary key; integer field type, autovalue)
- Date (date field type)
- Start_Time (time field type)
- End_Time (time field type)
- Field_Trip_Location (relates to Locations table)
- Weather
- Wind
- Temp (as text so 60s, etc. is allowed)
- Participants
- Comments
Sightings Table
- Sightings_ID (primary key; integer field type, autovalue)
- Bird_Name (relates to Birds Table)
- Sightings_Field_Trip_ID (relates to Field_Trips Table; integer field type)
- Male (Yes/No field type)
- Female (Yes/No field type)
- Juvenile (Yes/No field type)
- Voice (Yes/No field type) - bird identified by its voice
- Sight (Yes/No field type) - bird identified by sight.
- Comments (bird behavior, where cited, etc.)
- (Note: if tracking sightings for a family of birders, add two yes/no fields for each family member, one for voice and one for sight. e.g. JaneVoice, JaneSight, JohnVoice, JohnSight. I also discovered that it was handy to have a GuestVoice and a GuestSight field. That way if I am birding with a group I can add sightings by other members of the group. This is helpful for tracking information about birds seen at particular locations, for example.)
Locations Table
- Location_ID (primary key; integer field type, autovalue)
- Location_Name (relates to Field_Trips table)
- City
- County
- StateOrProvince (default value to your state)
- Country (default value to your country)
- Terrain_Type
- Water_Type
- Comments (memo(longvarchar))
Note There is no direct relationship between the Field_Trips Table and the Birds Table nor is there a direct relationship between the Locations Table and the Sightings Table or the Locations Table and Birds Table. But these tables can be related together in Queries, as long as the Query includes third table that does relate to the 'unrelated' tables. For example, while the Sightings Table and the Locations Table do not have a direct connection, the Field Trips table can act as an intermediary, as it relates to both of these tables.
Creating the Database Document
It is finally time to create a new database document.
- Under the File menu, choose New and then Database
- In the Database Wizard window, make sure the Create a new database radio button is selected.
- Click Next
- Make sure that the Yes, register the database for me and Open the Database for Editing settings are selected.
- Click Finish
The Next Steps
You are now ready to begin creating your tables. Table creation is covered in the following articles:
Be sure to keep your notes about the design of your database. More decisions will need to be made later. It will be easier to make those decisions if you can refer to this list of tables and fields.
Related External Links
- the Sum-it Database Design Course
- Books on database design from OOoForum.org
- OpenOffice.org Forum discussion on planning a database
- Wikipedia article on Database Normalization