diff --git a/database/media/schema.diagram b/database/media/schema.diagram new file mode 100644 index 0000000..f6a3b22 --- /dev/null +++ b/database/media/schema.diagram @@ -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"} \ No newline at end of file diff --git a/database/media/schema.png b/database/media/schema.png new file mode 100644 index 0000000..0d67e09 Binary files /dev/null and b/database/media/schema.png differ diff --git a/database/notes/02-integrity-er-diagram.md b/database/notes/02-integrity-er-diagram.md new file mode 100644 index 0000000..229e4ea --- /dev/null +++ b/database/notes/02-integrity-er-diagram.md @@ -0,0 +1,49 @@ +# Data Integrity and ER Diagrams + +![ERD](https://www.memecreator.org/static/images/memes/5074790.jpg) + +## 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. + +![Schema](../media/schema.png) + +!!! 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 +