Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Remove elements not following foreign key constaints
- DELETE from dbo.User_Release where userId NOT IN (SELECT id from dbo.releaseUser)
- DELETE from dbo.Comment where dbo.Comment.releaseId NOT IN (SELECT id from dbo.Release)
- DELETE from dbo.User_Release where releaseId NOT IN (SELECT id from dbo.Release)
- -- User release
- ALTER TABLE User_Release
- ADD FOREIGN KEY (userId)
- REFERENCES releaseUser(id)
- ON DELETE CASCADE;
- ALTER TABLE User_Release
- ADD FOREIGN KEY (releaseId)
- REFERENCES Release(id)
- ON DELETE CASCADE;
- -- Release
- ALTER TABLE Release
- ADD FOREIGN KEY (categoryId)
- REFERENCES Category(id)
- ON DELETE SET NULL;
- ALTER TABLE Release
- ADD FOREIGN KEY (userId_Owner)
- REFERENCES releaseUser(id)
- ON DELETE SET NULL;
- -- Comment
- ALTER TABLE Comment
- ADD FOREIGN KEY (releaseId)
- REFERENCES Release(id)
- ON DELETE CASCADE;
- ALTER TABLE Comment
- ADD FOREIGN KEY (userId)
- REFERENCES releaseUser(id)
- ON DELETE CASCADE;
- ALTER TABLE Comment
- ADD FOREIGN KEY (commentId_Reply)
- REFERENCES Comment(id)
- ON DELETE CASCADE;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement