ALTER TABLE media ALTER COLUMN mediaid SET WITH DEFAULT NULL
/
REORG TABLE media
/
ALTER TABLE media ALTER COLUMN userid SET WITH DEFAULT NULL
/
REORG TABLE media
/
ALTER TABLE media ALTER COLUMN mediatypeid SET WITH DEFAULT NULL
/
REORG TABLE media
/
ALTER TABLE media ALTER COLUMN period SET DEFAULT '1-7,00:00-24:00'
/
REORG TABLE media
/
DELETE FROM media WHERE userid NOT IN (SELECT userid FROM users)
/
DELETE FROM media WHERE mediatypeid NOT IN (SELECT mediatypeid FROM media_type)
/
ALTER TABLE media ADD CONSTRAINT c_media_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE
/
ALTER TABLE media ADD CONSTRAINT c_media_2 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE
/
