Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using two separate tables looks like a sensible approach here - the two tables seem to have very little in common. Combining unrelated objects into a single table and using NULLs for the columns that don't apply is typically a bad design.</p> <p>More generally though, if you have two types objects that are different in some respects but also share some common features then another alternative you could look into is a technique that is sometimes called "table inheritance":</p> <ul> <li><a href="https://stackoverflow.com/questions/386652/techniques-for-database-inheritance">Techniques for database inheritance?</a></li> <li><a href="http://www.sqlteam.com/article/implementing-table-inheritance-in-sql-server" rel="nofollow noreferrer">Implementing Table Inheritance in SQL Server</a></li> </ul> <p>In your first approach you use one table that contains all the data. In your second approach you use two tables that are completely separate. The inheritance approach uses three tables - one for the common columns, and an extra table for each specialized type. You then use a foreign key relationship to relate the record in the common table to a record in one of the specific tables so that you can join to get the complete object. There are a few different ways to create this relationship that are described in the article I linked to above.</p> <p>But don't overuse table inheritence. Two tables may happen to share a couple of columns for example (ID, insertion_date) but be otherwise two conceptually different things. Then it probably would not be appropriate to use this technique to factor out the common columns. I don't know enough about your specific situation to say whether it makes sense to use this technique on 'Wall posts' and 'Share a Link' posts, but you might want to consider it.</p> <p>To give an example of when it could be useful to use this technique rather than having two separate tables: If you want to query for a user's ten most recent posts (regardless of whether they are wall posts or shared links) then it is useful to have a single table where you can get the IDs for these posts with a single simple query. If you have two completely separate tables with no relationship between them the query is more complex - you must first get the top 10 from each table, union the results, then get the top 10 from the union.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload