Quantcast
Viewing all articles
Browse latest Browse all 207

Insert values and add values to foreign key

I have two tables:

CREATE TABLE est (  est_id serial PRIMARY KEY, est_nom varchar(70));CREATE TABLE bm (  id serial PRIMARY KEY, est_nom int, nom varchar(70), CONSTRAINT FK_bm_est FOREIGN KEY(est_nom) REFERENCES est(est_id) ON DELETE SET NULL);

I want to insert this data in bm

INSERT INTO bmVALUES(netx serial,'DAPR','leopold stotch'),(netx serial,'LDGA','fredderik gauss'),(netx serial,'SDCD','edward gortz')

Input values in column 2 are strings, corresponding to est.est_nom. I need the matching est.est_id instead.

I want to get existing values from est.est_nom and use them for the insert into bm.est_id.

If not found, first insert new rows in est and use the resulting serial est_nom for the insert into bm.


Viewing all articles
Browse latest Browse all 207

Trending Articles