Welcome Guest, Not a member yet? Register   Sign In
What's wrong with this code? =/
#11

[eluser]Abel A.[/eluser]
Ok, I get what you're trying to do now. For one, it's bad DBA to have multiple tables for different articles. The solution would be to merge all the article tables together and have a column to distinguished what type of article it is.

Article Table:
id, author, date, type

If you have columns that are unique to certain articles, then you can create a new table with the extra unique columns and have the Article id column as the foreign key. This way, you can just use a join for the extra fields.

Here's an example of a db structure:

Table articles:
articleid, author, title, date, opened, visible, type

Table user:
userid, username, email, password

Table comments:
commentid, articleid, commentbody, author, date


Now say that an entertainment article has unique columns that the rest of the articles don't have, then you can do this:

Table entertainment_extras:
articleid, unique1, unique2, unique3

articleid is the foreign key.

As you can see, you can just add extra tables and Join them. Alternatively, if you don't want to change your db structure then creating a view would be best.
#12

[eluser]emily12[/eluser]
Makes sense. I might just ignore this original problem and merge tables together instead. I thought it would be a fun experiment to do something ridiculously complex (inefficient but complex), however it seems like it may be too difficult. Thanks a lot, I had never thought of table_extras before, which is brilliant IMO!
#13

[eluser]Abel A.[/eluser]
Yeah, what you were doing sounded pretty complex lol

Though, it's always good to know how to use views. I once did it for a class project and it was no fun Sad

Creating table_extras is definitely a good solution, BUT it should only be used if you're not going to join both tables 100% of the time. If you're going to need the extra fields for each query, then you might as well use a view. Vertical partitioning comes in handy when you're not constantly calling the extra table.

You can read a bit about it here: http://en.wikipedia.org/wiki/Partition_(...ng_methods

What you were doing in your original db structure was horizontal partitioning, which should only be used if you have millions and millions of rows.

Good luck with your project! keep us updated!
#14

[eluser]emily12[/eluser]
Thanks for the advice, I have much to learn ^.^;




Theme © iAndrew 2016 - Forum software by © MyBB