PostgreSQLの外部キー制約を追加、削除する方法

1.追加
ALTER TABLE EMPLOYEE_MANAGE ADD FOREIGN KEY (USER_ID) REFERENCES USER_CFT(USER_ID)
ON
DELETE CASCADE;

2.表示
SELECT
*
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = ‘FOREIGN KEY’
AND TABLE_NAME = ‘EMPLOYEE_MANAGE’;

3.削除
ALTER TABLE EMPLOYEE_MANAGE DROP CONSTRAINT USER_ID

Comments are closed.