# ERD Examples

## University

We have a university where a Student enrolls in courses. A Student must be assigned to at least one or more Courses. Each Course is taught by a single Professor. A Professor can deliver only one course.

### Step 1: Entity Identification

* Student
* Course
* Professor

### Step 2: Relationship Identification

* Student is assigned a course
* Professor teaches a course

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-ad8547ffcbede5aaeddb65eae4e03b1a0e5c4cd4%2Fimage.png?alt=media" alt="" width="476"><figcaption></figcaption></figure>

### Step 3: Cardinality Identification

* A student can be assigned multiple courses
* A course can be enrolled by multiple students
* A professor can deliver only one course

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-c1bf39ea29f764b04cbe912a02a6c050c87efb81%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Step 4: Identify Attributes

* Student: StudentId, StudentName, StudentAge
* Course: CourseID, CourseName
* Professor: EmployeeId, ProfessorName, EmployeeAge

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-ae6436866efc9adec3ae93998ce9ff673bdb7e4e%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="success" %}
Note the underlined primary key attribute
{% endhint %}

### Step 5: Create ERD Diagram

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-2f708fc1ef48e12cd13794b2aead70eeb7b84d1c%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## MySQL Sample ERD Diagrams

### Employee - Department

<https://www3.ntu.edu.sg/home/ehchua/programming/sql/SampleDatabases.html>

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-51c98eadb83e291354b08a0b573fb23b682b3be7%2FSampleEmployees.png?alt=media" alt="" width="485"><figcaption></figcaption></figure>
