Question: in postgresSQL im trying to create a foreign key that links the first_name to the balance in the bank table im getting this error when
in postgresSQL im trying to create a foreign key that links the first_name to the balance in the bank table
im getting this error when i try and create it
SQL Error [23503]: ERROR: insert or update on table "bank" violates foreign key constraint "bank_balance_fkey" Detail: Key (balance)=(50000) is not present in table "accounts".
DROP TABLE IF EXISTS accounts; DROP TABLE IF EXISTS bank;
CREATE TABLE accounts ( id SERIAL, first_name VARCHAR(50) PRIMARY KEY, last_name VARCHAR (50), email VARCHAR (50), password VARCHAR (50), account_Type VARCHAR (10), bday VARCHAR (50) );
INSERT INTO accounts ( first_name, last_name, email, password, account_Type, bday) VALUES ('bob', 'john', 'bob@gmal.com', 'bob1','Manager', '01/01/1985'), ('Tom', 'lin', 'tom@gmal.com', 'tom1', 'Manager', '5/23/1990');
CREATE TABLE bank( balance VARCHAR(20) REFERENCES accounts(first_name) );
INSERT INTO bank( balance) VALUES ('50000'),('100000');
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
