Course Resources

Search

Search IconIcon to open search

Last updated Unknown

# Data Types and Nullability

In addition to showing basic structure of tables and their relationships, Entity Relationship Diagrams (ERDs) can also give us more insight into the columns. This can include data types for each column and whether a column can have null values. Let’s explore these concepts with an example diagram.

# College Courses Diagram

# Data Types

Each column in a table has a specific data type that dictates the kind of data it can hold to the right of its name. There are many different types but some of the most common are:

A full list of data types can be found here at W3Schools: SQL Data Types for MySQL, SQL Server, and MS Access (w3schools.com)

# Nullability

In addition to data types, ERDs can indicate whether a column can have a null value. A null value represents the absence of a value. Whether a field can be null or not depends on the business rules and data requirements:

Taking a look at the College Courses Diagram above, you’ll notice that each column in the tables has a defined data type. Some fields, like phone_number in the student table, are marked as nullable (indicated by varchar(11)?), meaning it is not mandatory for a record to have this information.

# Practice Questions

  1. Suppose we need to record the office_location for each instructor in the College Courses Diagram. What data type should this column be and should it be allowed to be null? Why?
  2. Imagine we want a last_accessed column in the enrollment table that tracks when a student last signed into their class on Canvas. What data type should this column be and should it be allowed to be null? Why?

# Back: SQL Analytics M6 - Entity Relationship Diagrams and Table Creation