-- hdb_disable_con_def.sql
--
-- HDB v4.00 Jeremy S. and Stan K.
--
--
-- Modified:
--          Apr 27,1999  Stan K.   Add droping NODE_PK and DEVICE_NODE_FK keys.
--          Jun 25,1999  Stan K.   Add droping DFLTS_DEV_TYPE_FK.
--          Jul 26,1999  Stan K.   v4.00
--          Mar 27,2000  Jeremy S  Added dropping PARAM_FK AND PARAM_PK
--          Mar 31,2000  Stan K.   Removed USR_TEMPL_PK
--                                 Added PARAM_TEMPL_FK
--          Jun  8,2000  Stan K.   Added NODE_LOCATOR_FK
--                                 Added DET_DEVS_PK, DET_DEVS_DET_FK,
--                                                    DET_DEVS_DEV_FK
--          Sep 15,2000  Vlad S.   Replace DEVICE_DEV_TYPE_FK by
--                                 DEVICE_TEMPL_ID_FK in DEVICE table
--          Sep 27,2000  Stan K.   Added GEN_PK, GEN_DEV_ID_FK
--          Oct 17,2000  Stan K.   Replaced TEMPL_PK by: TEMPL_RECORD_PK and 
--                                                       TEMPL_FIELD_PK
--                                 Replaced foreign keys on TEMPLATES: TEMPL_DEF_FK,
--                                                                     TEMPL_ID_FK
--                                 by:                                 TEMPL_FLD_DEF_FK,
--                                                                     TEMPL_REC_ID_FK.
--                                 Added foreign key TEMPL_FIELD_REC_FK.
--                                 Removed: RECORD_PK, FIELD_PK,
--                                 RECORD_DEV_ID_FK, FIELD_REC_FK, FIELD_DEF_FK.
--                                 Added: ALARM_PK, TEMPL_REC_ALARM_FK.
--          Apr 12,2002  Stan K.   Added check constraints DEV_CK and TEMPL_RECORD_CK
-- 
--

PROMPT Dropping Check Constraints on 'DEVICES'
ALTER TABLE DEVICES DROP CONSTRAINT
 DEV_CK
/

PROMPT Dropping Check Constraints on 'TEMPL_RECORDS'
ALTER TABLE TEMPL_RECORDS DROP CONSTRAINT
 TEMPL_RECORD_CK
/

PROMPT Disabling Foreign Keys on 'DETECTOR_DEVICES'
ALTER TABLE DETECTOR_DEVICES DROP CONSTRAINT
 DET_DEVS_DET_FK CASCADE
   DROP CONSTRAINT
 DET_DEVS_DEV_FK CASCADE
/

PROMPT Disabling Foreign Keys on 'NODES'
ALTER TABLE NODES DROP CONSTRAINT
 NODE_LOCATOR_FK CASCADE
/

PROMPT Disabling Foreign Keys on 'DEVICES'
ALTER TABLE DEVICES DROP CONSTRAINT
 DEVICE_TEMPL_ID_FK CASCADE 
   DROP CONSTRAINT
 DEVICE_DET_FK CASCADE 
   DROP CONSTRAINT
 DEVICE_LOCATOR_FK CASCADE
   DROP CONSTRAINT
 DEVICE_NODE_FK CASCADE  
/

PROMPT Disabling Foreign Keys on 'GENERATORS'
ALTER TABLE GENERATORS DROP CONSTRAINT
 GEN_DEV_ID_FK CASCADE
/
 
PROMPT Disabling Foreign Keys on 'TEMPLATE_IDS'
ALTER TABLE TEMPLATE_IDS DROP CONSTRAINT
 TEMPL_ID_DEV_TYPE_FK CASCADE
/

--PROMPT Disabling Foreign Keys on 'TEMPLATES'
--ALTER TABLE TEMPLATES DROP CONSTRAINT
-- TEMPL_DEF_FK CASCADE
--   DROP CONSTRAINT
-- TEMPL_ID_FK CASCADE
--/

PROMPT Disabling Foreign Keys on 'PARAMETERS'
ALTER TABLE PARAMETERS DROP CONSTRAINT
  PARAM_TEMPL_ID_FK CASCADE
/

PROMPT Disabling Foreign Keys on 'DEFAULTS'
ALTER TABLE DEFAULTS DROP CONSTRAINT
 DFLTS_DEF_FK CASCADE
/

--PROMPT  Disabling Foreign Keys on 'RECORDS'
--ALTER TABLE RECORDS DROP CONSTRAINT
-- RECORD_DEV_ID_FK CASCADE 
--/

--PROMPT Disabling Foreign Keys on 'FIELDS'
--ALTER TABLE FIELDS DROP CONSTRAINT
-- FIELD_REC_FK CASCADE
--   DROP CONSTRAINT
-- FIELD_DEF_FK CASCADE
--/

PROMPT  Disabling Foreign Keys on 'TEMPL_RECORDS'
ALTER TABLE TEMPL_RECORDS DROP CONSTRAINT
 TEMPL_REC_ID_FK CASCADE
   DROP CONSTRAINT
 TEMPL_REC_ALARM_FK CASCADE 
/

PROMPT Disabling Foreign Keys on 'TEMPL_FIELDS'
ALTER TABLE TEMPL_FIELDS DROP CONSTRAINT
 TEMPL_FIELD_REC_FK CASCADE
   DROP CONSTRAINT
 TEMPL_FLD_DEF_FK CASCADE
/

--PROMPT Disabling Primary Key on 'FIELDS'
--ALTER TABLE FIELDS
-- DROP CONSTRAINT FIELD_PK CASCADE
--/

--PROMPT Disabling Primary Key on 'RECORDS'
--ALTER TABLE RECORDS
-- DROP CONSTRAINT RECORD_PK CASCADE
--/

PROMPT Disabling Primary Key on 'TEMPL_FIELDS'
ALTER TABLE TEMPL_FIELDS
 DROP CONSTRAINT TEMPL_FIELD_PK CASCADE
/

PROMPT Disabling Primary Key on 'TEMPL_RECORDS'
ALTER TABLE TEMPL_RECORDS
 DROP CONSTRAINT TEMPL_RECORD_PK CASCADE
/

PROMPT Disabling Primary Key on 'ALARMS'
ALTER TABLE ALARMS
 DROP CONSTRAINT ALARM_PK CASCADE
/

PROMPT Disabling Primary Key on 'GENERATORS'
ALTER TABLE GENERATORS
 DROP CONSTRAINT GEN_PK CASCADE
/
  
--PROMPT Disabling Primary Key on 'TEMPLATES'
--ALTER TABLE TEMPLATES
-- DROP CONSTRAINT TEMPL_PK CASCADE
--/

PROMPT Disabling Primary Key on 'PARAMETERS'
ALTER TABLE PARAMETERS
 DROP CONSTRAINT PARAM_PK CASCADE
/

PROMPT Disabling Primary Key on 'TEMPLATE_IDS'
ALTER TABLE TEMPLATE_IDS
 DROP CONSTRAINT TEMPL_ID_PK CASCADE
/

PROMPT Disabling Primary Key on 'MENUS'
ALTER TABLE MENUS
 DROP CONSTRAINT MENU_PK CASCADE
/

PROMPT Disabling Primary Key on 'DEFAULTS'
ALTER TABLE DEFAULTS
 DROP CONSTRAINT DFLT_PK CASCADE
/

PROMPT Disabling Primary Key on 'LOCATORS'
ALTER TABLE LOCATORS
 DROP CONSTRAINT LOCATOR_PK CASCADE 
/

PROMPT Disabling Primary Key on 'NODES'
ALTER TABLE NODES
 DROP CONSTRAINT NODE_PK CASCADE 
/

PROMPT Disabling Primary Key on 'EPICS_DEFINITIONS'
ALTER TABLE EPICS_DEFINITIONS
 DROP CONSTRAINT EPICS_DEF_PK CASCADE 
/

PROMPT Disabling Primary Key on 'DEVICES'
ALTER TABLE DEVICES
 DROP CONSTRAINT DEV_PK CASCADE  
/

PROMPT Disabling Primary Key on 'DETECTOR_DEVICES'
ALTER TABLE DETECTOR_DEVICES
 DROP CONSTRAINT DET_DEVS_PK
/

PROMPT Disabling Primary Key on 'DEVICE_TYPES'
ALTER TABLE DEVICE_TYPES
 DROP CONSTRAINT DV_TYP_PK CASCADE  
/

PROMPT Disabling Primary Key on 'DETECTORS'
ALTER TABLE DETECTORS
 DROP CONSTRAINT DET_PK CASCADE  
/
                                         
commit
/
