Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions