开发者

Postgres: n:m intermediate table with type

开发者 https://www.devze.com 2023-03-30 12:47 出处:网络
I have a table called \"Tag\" which consists of an Id, Name and Description column. Now lets say I have the tables Character (C), Movie (M), Series (S) etc..

I have a table called "Tag" which consists of an Id, Name and Description column.

Now lets say I have the tables Character (C), Movie (M), Series (S) etc..

And I want to be able to tag entries in C, M, S with multiple tags and one tag may be used for multiple entries.

So I could realize it like this:

T -> TC <- C  
T -> TM <- M  
T -> TS <- S  

Where TC, TM, TS are the interme开发者_如何学JAVAdiate tables.

I was wondering if I could combine TC, TM, TS into one table with a type column added and still use foreign keys.

As of yet I haven't found a way to do it.

Or is this something I shouldn't be doing?


As the comments above suggested you can't combine multiple table into a single one. If you want to have a single view of the "tag relationships" you can pull the needed information into a View. This way, you only need to write a longer query once and are able to use like a single table. Keep in mind that you can't insert data into a view (there are possibilities to do so, but they are a little advanced)

0

精彩评论

暂无评论...
验证码 换一张
取 消