Choosing data types at table creation
It is best to specify the data type for a column when the table is initially created. The type can be changed later. However, this change may have unintended consequences if the column contains previously populated values. In this exercise, you will specify data types based on the category of data to which the values belong.
We will now return to the Small Business Association (SBA) database example from Chapter 1. SBA loans are provided for specific business projects. You will complete the definition of the project
table using the most appropriate column type.
This exercise is part of the course
Creating PostgreSQL Databases
Exercise instructions
- Complete the
CREATE TABLE
command for theproject
table using the correct data type from the following choices:TEXT
,BOOLEAN
, andNUMERIC
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Create the project table
___ ___ ___ (
-- Unique identifier for projects
id SERIAL PRIMARY KEY,
-- Whether or not project is franchise opportunity
is_franchise ___ DEFAULT FALSE,
-- Franchise name if project is franchise opportunity
franchise_name ___ DEFAULT NULL,
-- State where project will reside
project_state ___,
-- County in state where project will reside
project_county ___,
-- District number where project will reside
congressional_district ___,
-- Amount of jobs projected to be created
jobs_supported ___
);