Turn two database tables into one?

后端 未结 3 1200
借酒劲吻你
借酒劲吻你 2021-01-27 01:33

I am having a bit of trouble when modelling a relational database to an inventory managament system. For now, it only has 3 simple tables:

  1. Product

    
    
            
3条回答
  •  孤独总比滥情好
    2021-01-27 01:46

    The fact that headings are the same is irrelevant. Seeking to use a single table because headings are the same is misconceived.

    -- person [source] loves person [target]
    LOVES(source,target)
    
    -- person [source] hates person [target]
    HATES(source,target)
    

    Every base table has a corresponding predicate aka fill-in-the-[named-]blanks statement describing the application situation. A base table holds the rows that make a true statement.

    Every query expression combines base table names via JOIN, UNION, SELECT, EXCEPT, WHERE condition, etc and has a corresponding predicate that combines base table predicates via (respectively) AND, OR, EXISTS, AND NOT, AND condition, etc. A query result holds the rows that make a true statement.

    Such a set of predicate-satisfying rows is a relation. There is no other reason to put rows in a table.

    (The other answers here address, as they must, proposals for and consequences of the predicate that your one table could have. But if you didn't propose the table because of its predicate, why did you propose it at all? The answer is, since not for the predicate, for no good reason.)

提交回复
热议问题