I’ve created a database with a table (customer table) that holds basic customer information and a column that stores a percentage number for the week.
My issue is, I need to create a 2nd table (archive table) that stores all of these weekly,monthly and yearly percentage numbers and keeps it linked to the customer. (I’ll be using this to calculate averages)
Problem is, Even though I know I’ll have to use a foreign key I have NO IDEA how to implement it or even if/how to use a primary key for the archive table. Here’s an basic example of how it’s currently set up.
"""CREATE TABLE customer (id INTEGER PRIMARY KEY, name TEXT, percentage INTEGER)"""
now here is the archive table I’m trying to develop
"""CREATE TABLE archive(week INTEGER, month TEXT, year VARCAR)"""
I don’t even think I’ve created the right columns but for right now I need to know how would I set this archive table up so that it links to each customer and the numbers stored in the weekly, monthly, yearly columns.
You can create a reference from archive to the primary key in the customer table.
You might call the field customer_id, depending on your conventions.