删除外键和恢复外键

创建数据库的时候sql语句会有生成外键的语句:

 

//删除外键
alter table t_user_roles drop constraint fk_t_user_r_reference_t_user;
alter table t_city_manager drop constraint fk_t_city_m_reference_t_user;	
alter table t_attention drop constraint fk_t_attent_reference_t_user;
alter table t_bus_demand drop constraint fk_t_bus_de_reference_t_user;
alter table t_quote drop constraint fk_t_quote_reference_t_suppli;

//恢复外键
ALTER TABLE ONLY t_attention
    ADD CONSTRAINT fk_t_attent_reference_t_user FOREIGN KEY (w3_account) REFERENCES t_user(w3_account) ON UPDATE RESTRICT ON DELETE RESTRICT;

ALTER TABLE ONLY t_bus_demand
    ADD CONSTRAINT fk_t_bus_de_reference_t_user FOREIGN KEY (w3_account) REFERENCES t_user(w3_account) ON UPDATE RESTRICT ON DELETE RESTRICT;

ALTER TABLE ONLY t_city_manager
    ADD CONSTRAINT fk_t_city_m_reference_t_user FOREIGN KEY (w3_account) REFERENCES t_user(w3_account) ON UPDATE RESTRICT ON DELETE RESTRICT;

ALTER TABLE ONLY t_quote
    ADD CONSTRAINT fk_t_quote_reference_t_suppli FOREIGN KEY (supplier_id) REFERENCES t_supplier(supplier_id) ON UPDATE RESTRICT ON DELETE RESTRICT;

ALTER TABLE ONLY t_user_roles

    ADD CONSTRAINT fk_t_user_r_reference_t_user FOREIGN KEY (w3_account) REFERENCES t_user(w3_account) ON UPDATE RESTRICT ON DELETE RESTRICT;

 

你可能感兴趣的:(删除)