ctfs workshop shameema esufali suzanne lao data coordinators and technical resources for the network...
TRANSCRIPT
![Page 1: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/1.jpg)
CTFS Workshop
Shameema EsufaliSuzanne Lao
Data coordinators and technical resources for the network
[email protected]@si.edu
![Page 2: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/2.jpg)
CTFS WorkshopRelational database basics Why relational databases?
Why MySQL?
What about R?
![Page 3: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/3.jpg)
From an input sheet to a database
What is a database?Why do we need to convert our input sheet/
excel spreadsheet to a database?What are the advantages and
disadvantages?How does a data entry program help?
![Page 4: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/4.jpg)
Input form / Excel sheet
How best to store data for
Accuracy Easy retrieval
![Page 5: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/5.jpg)
![Page 6: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/6.jpg)
Relational Theory
In order to work with MySQL it is necessary to understand the basics of relational theory.
i.e how and why data is stored and managed in a relational database.
The guiding principle behind a relational database is to store data once and only
once.
![Page 7: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/7.jpg)
What is a Relation?
A table. Columns are fields (attributes) of data related to other fields on the
same row (tuple).
![Page 8: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/8.jpg)
Primary Key
Identifies the row of a table without duplicates.
Tells you what the row contains Eg. If treeid is the primary key then the row
has information about that tree
![Page 9: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/9.jpg)
Candidate Primary Key
Any attribute(s) which together would serve as the primary key.
Must uniquely identify a row of data. Each part of the key must be essential to unique
identification. No redundancy.
![Page 10: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/10.jpg)
Foreign Key
A foreign key is a column in a table that matches the primary key column of another table. Its function is to link the basic data of two entities on demand, i.e. when two tables are joined using the common key.
![Page 11: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/11.jpg)
First Normal Form
One piece of information per column. No repeated rows. Eliminate fused data eg Code1,Code2
Tag Species Code
1234 SHORME A
1234 SHORME BA
Tag Species Code
1234 SHORME A, BA
Wrong!
Right
![Page 12: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/12.jpg)
Second Normal FormEach column depends on the entire primary key.
Tag Census Species Seedsize X Y DBH
1234 1 SHORTR Medium 11.3
15.4 12
Tag Species Seedsize X Y
1234 SHORTR Medium 11.3
15.4
Wrong
Right
![Page 13: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/13.jpg)
Third Normal FormEach column depends ONLY on the primary key. i.e.
there are no transitive dependencies
Tag Species Seedsize X Y
1234 SHORTR Medium 11.3 15.4
Tag Species X Y
1234 SHORTR 11.3 15.4
Wrong
Right
![Page 14: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/14.jpg)
Fourth Normal FormThe table must contain no more than one
multi-valued dependency
Tag DBH Code
1234 10 A
1234 11 A
1234 11 BA
![Page 15: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/15.jpg)
Entity Relationship diagram (ERD)
Shows in a diagram how entities (tables) are related to one another.
One to One One to many Many to many
![Page 16: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/16.jpg)
One to one Extension of number of attributes in a single
table Rarely required
Tree More tree attributes
![Page 17: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/17.jpg)
One to Many
Most common
Requires two tables.
Linked by Foreign Key
Parent Child
Family Genus Species
![Page 18: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/18.jpg)
Many to many
Need to break down to one to many
Requires three tables
Associative table provides common key
Measurement Code
Tree Code
Measurement
![Page 19: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/19.jpg)
Reassembling data
Data was broken down into tables to preserve integrity
How can we put it together to derive information?
Use Structured Query Language (SQL) to JOIN tables using a common attribute
![Page 20: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/20.jpg)
Joins Two tables may be
joined when they share at least one common attribute
The Primary key of the Parent table is stored in the Child table as a cross reference. This is called a Foreign Key.
GenusID Genus FamilyID
1 Acacia 4
2 Acalypha 3
3 Adelia 3
4 Aegiphila 3
5 Alchornea 3
SpeciesID Species GenusId
1 melanoceras 1
2 diversifolia 2
3 macrostachya 2
4 triloba 3
5 panamensis 4
6 costaricensis 5
7 latifolia 5
Primary Key in Parent
Foreign Key in Child
![Page 21: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/21.jpg)
Table joined on Foreign Key GenusID
SpeciesID Species GenusId GenusID Genus FamilyID1 melanoceras 1 ⇿ 1 Acacia 42 diversifolia 2 ⇿ 2 Acalypha 33 macrostachya 2 ⇿ 2 Acalypha 34 triloba 3 ⇿ 3 Adelia 35 panamensis 4 ⇿ 4 Aegiphila 36 costaricensis 5 ⇿ 5 Alchornea 37 latifolia 5 ⇿ 5 Alchornea 3
The Genus ID in the Species table is used to pick up information for the corresponding Genus. It looks for a row with the matching Primary Key
![Page 22: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/22.jpg)
Extend to join many tables
With SQL you can join as many tables as you need to in order to get the set of information you need. Thus the previous example can be extended to include Family which is a parent table of Genus and/or extended in the another direction to include Tree which is a child of Species as long as there is a linking attribute. This attribute is called a Foreign Key.
![Page 23: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/23.jpg)
![Page 24: CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network shameemaesufali@gmail.com laoz@si.edu](https://reader036.vdocument.in/reader036/viewer/2022062518/56649eb05503460f94bb5fdb/html5/thumbnails/24.jpg)