How to enforce referential integrity on Single Table Inheritance?

后端 未结 4 2023
一生所求
一生所求 2021-02-19 09:11

I\'ve read some of Bill Karwin\'s answers about single table inheritance and think this approach would be good for the setup I am considering:

Playlist
--------
         


        
4条回答
  •  不思量自难忘°
    2021-02-19 09:33

    The answer by Zane Bien is quite obvious & superb.But I have an idea for doing this without use of trigger because trigger has many problems.

    Are you using any programming language ? If yes then,

    Use a single transaction and make your database auto commit false

    write a delete query for the referenced rows in Playlist and PlaylistVideo . Manually you have to write this query first by using that reference id(with where condition) and run it.

    Now prepare another query for your main task i.e. delete the User, and the rows in UserPlaylist will be deleted automatically ( due to CASCADE DELETE option).Now run your second query and commit.

    Finally make your transaction auto commit true.

    It is working successfully, hope it will helpful.

提交回复
热议问题