
USE parts;

SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning 
FROM INFORMATION_SCHEMA.TABLES 
WHERE 
        TABLE_SCHEMA = 'parts' 
    AND TABLE_NAME = 'DOG_Distraction'
;

CREATE TABLE IF NOT EXISTS parts.DOG_Distraction (
	  id_distraction INT NOT NULL AUTO_INCREMENT PRIMARY KEY
	, id_assessment INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_assessment
		FOREIGN KEY (id_assessment)
        REFERENCES parts.DOG_Assessment(id_assessment)
	, id_distraction_type INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_distraction_type
		FOREIGN KEY (id_distraction_type)
        REFERENCES parts.DOG_Distraction_Type(id_type)
	, id_intensity_level_emotional INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_intensity_level_emotional
		FOREIGN KEY (id_intensity_level_emotional)
        REFERENCES parts.DOG_Distraction_Intensity_Level(id_intensity_level)
	, id_intensity_level_scent INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_intensity_level_scent
		FOREIGN KEY (id_intensity_level_scent)
        REFERENCES parts.DOG_Distraction_Intensity_Level(id_intensity_level)
	, id_intensity_level_sight INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_intensity_level_sight
		FOREIGN KEY (id_intensity_level_sight)
        REFERENCES parts.DOG_Distraction_Intensity_Level(id_intensity_level)
	, id_intensity_level_sound INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_intensity_level_sound
		FOREIGN KEY (id_intensity_level_sound)
        REFERENCES parts.DOG_Distraction_Intensity_Level(id_intensity_level)
	, id_intensity_level_touch INT NOT NULL
    , CONSTRAINT FK_DOG_Distraction_id_intensity_level_touch
		FOREIGN KEY (id_intensity_level_touch)
        REFERENCES parts.DOG_Distraction_Intensity_Level(id_intensity_level)
	, quantity INT
    , proximity_metres FLOAT
    , notes TEXT
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Distraction_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES parts.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Distraction_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES parts.DOG_Dog_Change_Set(id_change_set)
);
