How do you declare foreign key in db2?

1 answer

Answer

1111753

2026-04-28 05:25

+ Follow

-- two dashes mean a comment in DB2 for VM and z/OS

-- 1st design your table - considered optional

-- 2nd declare your table - maditory. You still can not alter a table that

-- does not exist

-- 3rd alter the table to add the foreign key

-- DB2 for FOREIGN KEY

ALTER TABLE owner.Tablename

ADD CONSTRAINT name FOREIGN KEY (column name(s) )

REFERENCES REDBA.RESF_FINAL_CARD (column name(s) )

ON DELETE RESTRICT -- means stop them

or

ON DELETE cascade -- Cascade means to delete everthing here

or

ON DELETE SET value -- update the value of the column

;

-- note since you are doing DDL not dml the commit is implicit!! so

-- there is no COMMIT WORK needed

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.