The customer table

This article introduces the structure of the customer table in the Sakila database.

The customer table contains a list of all customers.

The customer table refers to the the address and store tables using a foreign key.

The payment and rental tables refers to the city table using a foreign key.

Table Structure

The structure of the customer table is as follows:

+-------------+-------------------+------+-----+-------------------+-----------------------------------------------+
| Field       | Type              | Null | Key | Default           | Extra                                         |
+-------------+-------------------+------+-----+-------------------+-----------------------------------------------+
| customer_id | smallint unsigned | NO   | PRI | NULL              | auto_increment                                |
| store_id    | tinyint unsigned  | NO   | MUL | NULL              |                                               |
| first_name  | varchar(45)       | NO   |     | NULL              |                                               |
| last_name   | varchar(45)       | NO   | MUL | NULL              |                                               |
| email       | varchar(50)       | YES  |     | NULL              |                                               |
| address_id  | smallint unsigned | NO   | MUL | NULL              |                                               |
| active      | tinyint(1)        | NO   |     | 1                 |                                               |
| create_date | datetime          | NO   |     | NULL              |                                               |
| last_update | timestamp         | YES  |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
+-------------+-------------------+------+-----+-------------------+-----------------------------------------------+

Table Columns

The following table explains all columns in the customer table.

Column Description
customer_id The surrogate primary key used to uniquely identify each customer in the table.
store_id A foreign key that identifies the customer’s “nearby store”. Customers not only rent from this store, but they also shop in this store.
first_name The customer’s first name.
last_name The customer’s last name.
email Customer email address.
address_id A foreign key that identifies the customer’s address in the address table.
active Indicates whether the customer is an active customer. Set this FALSE as an alternative to physically delete the customer. Most queries should have a WHERE active = TRUE clause.
create_date The date when the customer was added to the system. This date is automatically set using a trigger during `INSERT.
last_update The time when the row was created or last updated.