mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-03-15 23:19:56 +00:00
Draft commit - Integrity & ER.
This commit is contained in:
parent
3008cd3e43
commit
adf45c80da
1
database/media/schema.diagram
Normal file
1
database/media/schema.diagram
Normal file
@ -0,0 +1 @@
|
||||
{"type":"edit","version":3,"columns":[{"id":0,"value":{"id":"0","name":"name","type":"string"}},{"id":1,"value":{"id":"1","name":"type","type":"string"}},{"id":2,"value":{"id":"2","name":"nullable","type":"boolean"}}],"tables":[{"value":{"rows":[{"id":0,"value":{"id":"id","name":"id","type":"int","nullable":"true"}},{"id":1,"value":{"id":"name","name":"name","type":"varchar(255)","nullable":"true"}},{"id":2,"value":{"id":"start_date","name":"start_date","type":"timestamp","nullable":"true"}},{"id":3,"value":{"id":"type","name":"type","type":"varchar(255)","nullable":"true"}},{"id":4,"value":{"id":"mentor_id","name":"mentor_id","type":"int","nullable":"true"}}],"name":"batches","id":"batches","schema":"db"},"position":{"top":96,"left":448},"id":0,"rowsExpanded":false,"selected":false},{"value":{"rows":[{"id":0,"value":{"id":"id","name":"id","type":"int","nullable":"true"}},{"id":1,"value":{"id":"name","name":"name","type":"varchar(255)","nullable":"true"}},{"id":2,"value":{"id":"age","name":"age","type":"int","nullable":"true"}},{"id":3,"value":{"id":"phone","name":"phone","type":"int","nullable":"true"}},{"id":4,"value":{"id":"address","name":"address","type":"varchar(255)","nullable":"true"}},{"id":5,"value":{"id":"email","name":"email","type":"varchar(255)","nullable":"true"}}],"name":"mentors","id":"mentors","schema":"db"},"position":{"top":80,"left":832},"id":1,"rowsExpanded":false,"selected":false},{"value":{"rows":[{"id":0,"value":{"id":"id","name":"id","type":"int","nullable":"true"}},{"id":1,"value":{"id":"name","name":"name","type":"varchar(255)","nullable":"true"}},{"id":2,"value":{"id":"age","name":"age","type":"int","nullable":"true"}},{"id":3,"value":{"id":"phone","name":"phone","type":"int","nullable":"true"}},{"id":4,"value":{"id":"email","name":"email","type":"varchar(255)","nullable":"true"}},{"id":5,"value":{"id":"address","name":"address","type":"varchar(255)","nullable":"true"}},{"id":6,"value":{"id":"batch_id","name":"batch_id","type":"int","nullable":"true"}}],"name":"students","id":"students","schema":"db"},"position":{"top":64,"left":64},"id":2,"rowsExpanded":false,"selected":false}],"refs":[{"id":0,"from":{"table":0,"rows":[4]},"to":{"table":1,"rows":[0]},"selected":false},{"id":1,"from":{"table":2,"rows":[6]},"to":{"table":0,"rows":[0]},"selected":false}],"size":{"width":1568,"height":1003},"schema":"db"}
|
BIN
database/media/schema.png
Normal file
BIN
database/media/schema.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
49
database/notes/02-integrity-er-diagram.md
Normal file
49
database/notes/02-integrity-er-diagram.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Data Integrity and ER Diagrams
|
||||
|
||||

|
||||
|
||||
## Agenda
|
||||
* Data Integrity
|
||||
* ER Diagrams
|
||||
* Functional Dependencies
|
||||
* Normalization
|
||||
|
||||
## Key Terms
|
||||
### Schema
|
||||
> refers to the organization of data as a blueprint of how the database is constructed
|
||||
|
||||
> In a relational database, the schema defines the tables, fields, relationships, views, indexes, packages, procedures, functions, queues, triggers, types, sequences, materialized views, synonyms, database links, directories, XML schemas, and other elements
|
||||
|
||||
### Data Integrity
|
||||
### Entity Integrity
|
||||
### Referential integrity
|
||||
### Domain integrity
|
||||
### User-defined integrity
|
||||
### ER Diagrams
|
||||
|
||||
## Schema
|
||||
A schema is a blueprint of a database. It is created before you actually construct the database so that the schema design can be reviewed. Schema diagrams are also a great way to document the database structure in one place.
|
||||
|
||||
Remember our student's database from the [previous lesson](01-database-fundamentals.md)? We had the three following tables
|
||||
* `students` (id, name, age, address, phone, email, batch ID)
|
||||
* `mentors` (id, name, age, address, phone, email)
|
||||
* `batches` (id, name, mentor, start date, type, mentor ID)
|
||||
|
||||
So each table has `ID` as primary key. The `students` table has a `batch ID` field that references the `batches` table and the `batches` table has a `mentor ID` field that references the `mentors` table. These are examples of foreign keys. These are some the items that are present in a schema. A schema will also contain indexes, constraints, and other items that are present in a table.
|
||||
|
||||
Following is a schema diagram for the above database. Note that the primary key is not highlighted here, which ideally should be.
|
||||
|
||||

|
||||
|
||||
!!! Note Try it yourself
|
||||
Go to [this](https://diagramplus.com/) website and import [this](../media/schema.diagram) diagram. Try adding a new column or even a new table.
|
||||
|
||||
---
|
||||
## Data Integrity
|
||||
|
||||
---
|
||||
## ER Diagrams
|
||||
---
|
||||
## References
|
||||
## Reading List
|
||||
|
Loading…
x
Reference in New Issue
Block a user