Write a postgre SQL statement to insert rows into the job_history table in which one column job_id is containing those values which exist in job_id column of jobs table
Write a postgre SQL statement to insert rows into the job_history table in which one column job_id is containing those values which exist in job_id column of jobs table.
The value against job_id is 1001 which is exists in the job_id column of the jobs table, so no problem arise.
Now insert another row in the job_history table.
INSERT INTO job_history VALUES(502,1003,80);
Here is the output:
postgres=# INSERT INTO job_history VALUES(502,1003,80);
ERROR: insert or update on table "job_history" violates foreign key constraint "job_history_job_id_fkey"
DETAIL: Key (job_id)=(1003) is not present in table "jobs".
Here is the code to create a sample table jobs:
Now insert two rows in the jobs table.
Here is the command to see the list of inserted rows :
Here is another table:
Now insert the rows in the job_history table.
Here is the command to see the list of inserted rows:
The value against job_id is 1001 which is exists in the job_id column of the jobs table, so no problem arise.
Now insert another row in the job_history table.
Here is the output:
need an explanation for this answer? contact us directly to get an explanation for this answer