I can't seem to wrap my head around what should be the primary key in my Portfolio table. I am able to get a quote, buy a stock, and have the price taken from the corresponding user but my Portfolio table does not have a primary key. I read that all tables should have Primary keys and first hand am experiencing why now with
I didn't finish CS50 last year and started back up this year at CS50 Finance and it was proven difficult to jump back into so I've gone back and reviewed the previous weeks materials that relate to Python and SQL short of doing the PSETs.
I guess maybe some code would help to show what I have done up to this point when I create my Portfolio table.
rows = db.execute("CREATE TABLE IF NOT EXISTS Portfolio(stock text NOT NULL, shares int NOT NULL, price float NULL, transaction_time NOT NULL)")
Rather than going on and posting code, could someone please point me in the right direction or even provide reading materials? I understand that the user_id can't really be used as a primary key because then the user would not be able to buy a stock more than once. I feel like something like a joint (composite?) Primary Key with the
user_id would work but, how do I bring in the user id? I can't see how the second (maybe third?) tables could work without the user_id being involved somewhere.