Page 1 of 1

Merging database???

Posted: Thu Aug 16, 2007 12:59 am
by kkonline
I HAVE TWO TABLES ARTICLE AND STORY BOTH HAVING DIFFERENT STRUCTURE

However as insisted by experts if i do merge them and make one table then i will have many values as NULL in the db. And secondly i can have another field whose having 1/0 implies it being an article or story.

For example a field has default value 0 in article then i will have to put a default value (wen posted from form) to be NULL as that field will not be applicable to story

Is this type of discrimination and having a lot of db values as null fine?

If i can merge then the search will be easy... I can have a tags field for both articles and stories which will be something like keyword similar to that in FLICKR!

So pls explain should i merge?... Now that i will have only one db...

what abt the site security if i have 2 db or 1 db... i feel having one form sql injected will only affect that db [though the structure is complicated to work with] but other one would be safe is that the case?

Posted: Thu Aug 16, 2007 1:39 am
by s.dot
You have two databases, or two tables?

If the first is the case, it seems you should only have one database. If the second is the case, two tables is fine. If it makes logical sense to merge the tables, and promotes normalisation of the database, then yes, merge them. NULL values are fine.. doesn't make any difference. As far as security goes.. if one query gets injected, then your whole database is at risk, so it doesn't matter how many tables you have.

So, it's up to you on whether or not you want to merge the tables. But it sounds to me like you have a `stories` table and an `articles` table, which sounds pretty good.

Re: Merging database???

Posted: Thu Aug 16, 2007 5:46 am
by superdezign
kkonline wrote:If i can merge then the search will be easy...
Searches don't need to be easy, they just need to be possible. Most of the time. if you have to *think* about merging tables, you should probably leave them separate. Your database should technically be as organized to the human eye as it will be to your scripts if you plan to manage it at all.

Posted: Thu Aug 16, 2007 7:52 am
by kkonline
Dear Scottayy,
thanks for your prompt reply.

I have 2 tables (which i am concerned right now)These are quotes/quotations and articles/news. Both of them are completely different except they will have a tags and id field that exists in both. the quote table has fields like id, mood, quote, author. and news table has fields like id, posterid, postername, mood, catid, breaks, moral, subject, titletext and maintext.

So seeing this structure of the table what would you suggest. I think i'll go for different tables as it would be easy to understand and i work.

Another important thing, is search. Is it possible to search for a query from two different tables simultaneously and then show the results. I mean if a visitor searches for the keywork "goal" then all the results from the quotes and articles both; having tags or content field
as goal should be displayed; with only one search.


If yes then can you please suggest some code or an example on how to do it

Posted: Thu Aug 16, 2007 12:48 pm
by califdon
A relational database is a model of some part of the real world. A table should represent some definable entity. An entity is a person, an object, an event, a transaction, etc. If a quote is the same entity as an article, then they should be in the same table. If they are not the same entity, they should definitely not be in the same table. It's as simple as that. If you understand relational databases, there is seldom any ambiguity. What the other contributors said is correct, but I like to get down to fundamentals, so that the next time you are faced with such a question, you won't need to be confused. Just apply the logic.