Re: Turning Referential Integrity on/off
Posted in 1994
->Subject: Turning Referential Integrity on/off ->Date: Tue, 23 Aug 1994 07:35:16 GMT ->Reply-To: oli@environ.se (Vrjan Lindberg) ->Organization: Swedish Environmental Protection Agency -> ->I wonder if there is a way of turning referential integrity on and off. -> ->create table cust_calls -> ( -> customer_num integer, -> call_dtime datetime year to minute, -> user_id char(18) default user, -> call_code char(1), -> call_descr char(240), -> res_dtime datetime year to minute, -> res_descr char(240), -> primary key (customer_num, call_dtime), -> foreign key (customer_num) references customer (customer_num), -> foreign key (call_code) references call_type (call_code) -> ); -> ->The foregn key statement defines the referential integrity but is there a ->way of defining it after the table has been created and/or dropping it ->once it has been defined. I'm in the process of defining a database and ->too much referetial integrity is an obstacle when trying to load the ->database but handy during test and in a live environment. -> ->Orjan Lindberg ->Swedish EPA ->oli@environ.se You need to use the ALTER TABLE ... { ADD | DROP } CONSTRAINT ... commands. This will also encourage you to specify names for your constraints, which is a good idea, IMHO. Define your table(s) without any constraints, or maybe only UNIQUE constraints. Do your data loading; then add your constraints. This has the added advantage that the indexes that lurk behind PRIMARY KEY constraints will only be built after the load, rather than wasting effort to maintain them during the data load. I don't recall whether indexes are built for FOREIGN KEYs, but the same logic applies. Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, SLS | / \\ alan@den.mmc.com | P.O. Box 179, M/S 3810 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\