Q&A 9 How do I create and load a new table for GDP growth factors in MySQL?

9.1 Explanation

Your database may contain different types of economic data:
- GDP levels (in US dollars) → stored in a table like gdp_wdi
- GDP growth factors (growth rate + explanatory variables) → should be stored in a separate table

Keeping them separate avoids confusion and lets you query each dataset appropriately.
For this example, we will use a sample file: data/gdp_growth_factor.csv.


9.2 SQL/MySQL Code

-- 1. Drop table if it already exists (clean slate)
DROP TABLE IF EXISTS gdp_growth_factors;

-- 2. Create new table with growth rate + explanatory factors
CREATE TABLE gdp_growth_factors (
  country CHAR(3),
  year INT,
  gdp_growth_rate DOUBLE,
  investment DOUBLE,
  inflation DOUBLE,
  population_growth DOUBLE,
  PRIMARY KEY (country, year)
);

-- 3. Load CSV data into this new table
LOAD DATA LOCAL INFILE '/Users/tmbmacbookair/Dropbox/GITHUB_REPOs/cdi-economics/data/gdp_growth_factor.csv'
INTO TABLE gdp_growth_factors
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(country, year, gdp_growth_rate, investment, inflation, population_growth);

-- 4. Verify the first few rows
SELECT * FROM gdp_growth_factors LIMIT 5;

9.3 Learning Outcome

By the end of this Q&A you will be able to:

  • Create a new table specifically for GDP growth factors.
  • Load a CSV file into MySQL without overwriting your GDP levels table.
  • Keep your database organized and modular (one table = one type of data).

9.4 Takeaway

Always keep GDP levels and GDP growth factors in separate tables. This way, you can analyze absolute size (gdp_wdi) and explanatory variables (gdp_growth_factors) independently — or join them later if needed.