Computer HardwareXbox GamesGameCubePlaystation 2PSOnePC/Windows GamesGameboy AdvanceDreamcastNintendo 64Gameboy ColorNintendo DSSony PSPXbox 360Nintendo Wii GamesPS3 Games

Neoseeker is giving away:
3 copies of Lego Batman
2 copies of Gears of War 2
3 copies of 007 Quantum of Solace
4 of Call of Duty: World at War
1 copy of Castlevania DS
Neoseeker Forums » Programming and Design » Web Coding » Building a Database

Moderated by: Kuldahar,  Artificer
REPLY TO THIS THREAD   START NEW THREAD
Options: Print   subscribe   remove   send to friend   PM this thread to a friendNeoPM
Topic: Building a Database
Artificer
Aug 23, 08 at 3:21pm
Building a Database

What really goes into making a database? Should you design it in a certain way? Are there rules of what you should or should not do?

Look at a forum like Neoseeker, for example. Almost everything you see is the result of interaction with a database: forums, threads, posts, PMs, breadcrumb trails, preferences, and so on.

My goal for this thread is to discover a process of designing a database with all of you. To do this I've been considering designing a forum system DB because it seems to be the bond that ties all of us together. We all have some familiarity with what features Neoseeker offers, so it gives us a good base line from which to start.

The focus should be on what you want to learn, so before we start, I'd like to know: is this a useful exercise? What do you want to learn about database design?

[size=1][color=#666666]This message was edited by Artificer on Aug 23 2008.



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
Members, log in or register to remove these ads.
lord monkey
Rock Me Sexy Jesus
s-e-e-k-e-r

wiki staff
dynastywarriors




lord monkey's profilelord monkey's neohomeEmail lord monkeyNeoPM lord monkey
total posts: 1741
GameGrep pts: 394
since: Jun 2003
Aug 23, 08 at 3:34pm
re: Building a Database

I think this is great. We don't really have any database specific threads around here like this.

I think that we should start by showing the different types of databases out there, like MySQL, MsSQL, etc. Also some tools that you could use to administrate the databases in manually input info.

Then some site specific tables, such as members, forums, threads, posts, online_members, preferences, permissions.

Afterwards some smaller things, like favorite_forums.



-------------------
quote   quick quote   edit   quick edit   del  report
Vermillion
Aug 23, 08 at 6:23pm
re: Building a Database

Yeah, an introduction to the different Databases like MySQL, MySQL Lite, Oracle, and so on, sounds good.

Then we could continue with the datatypes, like the most common ones (int, varchar, and so on), to the "special" ones (bool, time, date, timedate, and so on).

Then the different tools to manage databases, like PhpMyAdmin or SQLLite Manager.

Then the specific tables and how they could work and interact with the pages.




-------------------

To Experience Is To Live.
To Live Is To Sheer Magic!
Devpen
quote   quick quote   edit   quick edit   del  report
Artificer
Aug 23, 08 at 7:18pm
re: Building a Database

What about before all of the stuff you (lord monkey and Vermillion) have mentioned? I know that the issues you've brought up are important, but...

...You have to start somewhere, and in most controlled scenarios it will not begin with making tables in MySQL, for example. First you have to know what data you're even interested in, right? Otherwise, how do you know you are designing your database appropriately?

From there, there are a few approaches you can take to get to your DB tables, but I can talk about those along the way. Mostly those extra steps involve organizing that data into a format that can be translated into an actual database implementation, and that's the point where you can start worrying about questions like "Which DBMS (Database Management System) should I choose?" and "What data types should I use?"

The point is that there's a lot out there in terms of DB design that tends to get overlooked, sometimes to a fault.



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
Vermillion
Aug 23, 08 at 7:37pm
re: Building a Database

You mean like how to organize my tables on a database for my forum? Or like "What Data do I need to create a moderator"?



-------------------

To Experience Is To Live.
To Live Is To Sheer Magic!
Devpen
quote   quick quote   edit   quick edit   del  report
Artificer
Aug 23, 08 at 8:02pm
re: Building a Database

If by "organize my tables" you mean deciding on which columns go where, then it's a bit of both. On the one hand, you have to know what you want. (In some cases, you're not the person who decides what is wanted, so this is really important.) Once you know what you want, you have to figure out how to structure it into a database (if you even decide to use a database).



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
Artificer
Aug 25, 08 at 6:41pm
re: Building a Database

So let's say before we think about MySQL, before we even think about databases or tables, our first step is to gather the data we want to store. In this case we are the ones who define what we need, so it makes this step a little easier.

What is the bare minimum we would need to make a forum?

I can name some of the objects in our business domain* right off the bat: forums and threads. What data about forums and threads would we need? Would we need any other objects in our domain? (Remember, we're thinking of the bare minimum, and think of the forums in terms of objects, not tables.)

*By business domain I mean the part of the universe that we are concerned with. In this case, it's forums, and the objects surrounding forums. It would most likely not involve objects like cars, famous buildings, or house furniture.



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
lord monkey
Rock Me Sexy Jesus
s-e-e-k-e-r

wiki staff
dynastywarriors




lord monkey's profilelord monkey's neohomeEmail lord monkeyNeoPM lord monkey
total posts: 1741
GameGrep pts: 394
since: Jun 2003
Aug 25, 08 at 6:52pm
re: Building a Database

So for bare minimum for a forum, you would need a unique id for each one, a title, maybe a description, and permissions, but thats going over board.

As for threads, they would get more complex. Again, a unique id, and a title, but also a bool value for if the thread is locked and/or sticky.

Furthermore, posts. A unique id, the actual message, the member posting the message, the IP address of the client posting the message for security issues, and the date of the message being posted.



-------------------
quote   quick quote   edit   quick edit   del  report
Artificer
Aug 25, 08 at 6:58pm
re: Building a Database

Let's say that we don't care about description, permissions, locking threads, stickying threads, or IP address of the poster for this example. Those are good ideas though, so keep them in mind for later.

That leaves us with the following:

Forums which have IDs and titles.
Threads which have IDs and titles.
Posts with IDs, messages, member posting the message, and the date.

Ah, but what is the member? Another object? What do we care about with regard to members?

Also, why would you need an ID for each of those objects? Or would you need an ID at all?



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
tekmosis
neostaff

wiki staff
neowiki




tekmosis's profiletekmosis's neohome
total posts: 2079
GameGrep pts: 5992
since: Jul 2006
Aug 25, 08 at 8:58pm
re: Building a Database

btw, if any of you are going to a post secondary institute where you'll be going over DB design, they'll highly favor normalization. My classes all loved going to 3rd normal at most. Normalization == crap in a lot of real world practices.

Anyways, I think you guys are being too specific to start out with. Be more generalized and then work from there. Good DB design comes down to planning, incorporated into planning is thinking into the future, which, means taking scalability into a vast consideration of your design.

  • Individual forums
  • Threads
  • Users
That's all you need for a basic forum. Start there then expand off of that in terms of features, etc.

Also, with scalability you'll always want to reference the data types overhead:
http://dev.mysql.com/tech-resources/articles/visual-basic-datatypes.html (actually may not be it, you want the specific MySQL only version of the data type charts but MySQL's site is absolutely horrible and I'm not going to put in more than 5mins to try to have to find it.)

After you figure out your column structure you should determine what type of tables you want based on their functionality (ie: InnoDB vs MyISAM) and why the other would be better over the other. Each type has their advantages and disadvantages.

code
Forums
-------------
forum_id
parent_id
forum_name
date_created
total_threads *

Threads
-------------
thread_id
forum_id
title
created_by
created_on
last_reply_by *
last_reply_on *
total_posts *

Users
-------------
user_id
username
password
registered_on


Take note of the fields I've stared. In school they'll teach you that you need another table(s) for those bits of information. However, that just means more table joins and results in a higher overhead. This is why I say that normalization in a lot of real world scenarios just doesn't cut it. Also take note that I've stuck to a consistent pattern with my fields, all id fields are separated as such <descriptor>_id. I don't mix it up like forumid, member_id. I also opted not to stick with the same field names in the threads table for the user_id. Rather than being ambiguous just by looking at the table you know that created_by is the memberid belonging to the person who created the thread.

For organization you can also do database schema's which map out table relations. Ex:
http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database-schema.png
I just recommend glancing at it and not to read into it too much. It's not the easiest thing to grasp and may just end up frustrating you and make you think that db design is for the extremely crazy. I do schemas a lot at work but nothing fancy like that, I just use a pen and paper. I actually had a situation last week where I needed to do a small schema of MediaWiki so I could figure out their insane structure for this neoseeker feature otherwise you just get confused with data relations too easily and end up wasting time while getting frustrated.

Wow, this is getting a bit long. Can you tell I like db design? ;P It was always one of my favorite topics in school. Although, from working at Neo and with Red I've learnt far more than I ever did in school.

This message was edited by tekmosis on Aug 25 2008.



-------------------
Do you <3 Faith? Win a copy of Mirrors Edge!
quote   quick quote   edit   quick edit   del  report
Liam
Liam
NeoXtreme



Liam's profileLiam's neohomeNeoPM Liam
since: Dec 2001
Aug 26, 08 at 2:44am
re: Building a Database

Tekmosis, how comes you choose to include the stared fields at all? Obviously all of which can be generated by SQL statements anyway (count, most recent date etc.), do you find it is more server friendly? I guess it does make queries more simple yet also means more queries when adding/removing threads.

I do try to incorporate normalisation in to my databases, but usually keeping it simple is best. As long as you are aware of primary and foreign keys and plan ahead you should be fine!

quote   quick quote   edit   quick edit   del  report
Artificer
Aug 26, 08 at 3:26am
re: Building a Database

quote tekmosis
btw, if any of you are going to a post secondary institute where you'll be going over DB design, they'll highly favor normalization. My classes all loved going to 3rd normal at most. Normalization == crap in a lot of real world practices.
Totally disagree. I understand that denormalization is favored when you have performance problems in your database, but doesn't Neoseeker have a few problems with denormalization? I've noticed situations where data updates in one location, but it doesn't seem the update is made in all the places it should be. IM me for an example—it's in the mod forum.

Also the starred fields you have laid out do not demonstrate denormalization; they are simply derived columns. As Liam said, better SELECT performance, but poorer INSERT/UPDATE/DELETE performance. I agree that is probably appropriate in Neoseeker's case since the most common use case would be browsing forums, etc. As long as you can keep those derived values updated, then sure, it's a good idea.

Bare with me, tek. I prefer not designing DBs at the physical table structure level but with another technique that doesn't even involve normalization theory. At the worst, you'll think I'm totally wrong, but hey, that's a risk I'm willing to take.

[size=1][color=#666666]This message was edited by Artificer on Aug 26 2008.



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
tekmosis
neostaff

wiki staff
neowiki




tekmosis's profiletekmosis's neohome
total posts: 2079
GameGrep pts: 5992
since: Jul 2006
Aug 26, 08 at 10:08am
re: Building a Database

The forums were coded back in 1990-esq(?) so using the forums as an example doesn't really hold water to the topic.

Actually, the columns I starred demonstrate denomalization very well. I believe it was Rasmus Lerdorf (creator of PHP) mentioned during a PHP seminar that the target number of queries you want to run on a page is 6.

It doesn't make sense to do two queries when you can do everything in a single query and without having to do multiple joins. The worst thing you can do is n+ queries.

Say you're listing all the forums and there's 30 total. Why would you want to run 31 queries versus 1? (one query to grab all the forums and then another query per forum to get the total number of threads). The query itself may be fast but still, why would you want n+ over a single query? :S

This message was edited by tekmosis on Aug 26 2008.



-------------------
Do you <3 Faith? Win a copy of Mirrors Edge!
quote   quick quote   edit   quick edit   del  report
Artificer
Aug 26, 08 at 10:31am
re: Building a Database

quote tekmosis
The forums were coded back in 1990-esq(?) so using the forums as an example doesn't really hold water to the topic.
Well, that's surprising to hear. We can discuss other things then.

quote tekmosis
Actually, the columns I starred demonstrate denomalization very well. I believe it was Rasmus Lerdorf (creator of PHP) mentioned during a PHP seminar that the target number of queries you want to run on a page is 6.
Just because you have a fewer number of queries doesn't mean you are denormalizing. The tables you showed are still in at least 3rd normal form.

quote tekmosis
It doesn't make sense to do two queries when you can do everything in a single query and without having to do multiple joins. The worst thing you can do is n+ queries.

Say you're listing all the forums and there's 30 total. Why would you want to run 31 queries versus 1? (one query to grab all the forums and then another query per forum to get the total number of threads). The query itself may be fast but still, why would you want n+ over a single query? :S
You would actually do the same number of queries by doing what Liam suggested; you would just have an extra join.

You do have more queries to run using your method when inserting/updating/deleting since you have to update the derived value (e.g. total_threads) as well.

[size=1][color=#666666]This message was edited by Artificer on Aug 26 2008.



-------------------

Pandora.com | Thinkers perish; thoughts don't.
quote   quick quote   edit   quick edit   del  report
tekmosis
neostaff

wiki staff
neowiki




tekmosis's profiletekmosis's neohome
total posts: 2079
GameGrep pts: 5992
since: Jul 2006
Aug 26, 08 at 10:36am
re: Building a Database

http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html#06
No, my tables are not 3rd normal.

Also, reading that page on 3NF you'll see this statement:

quote
A complete normalization of tables is desirable, but you may find that in practice that full normalization can introduce complexity to your design and application. More tables often means more JOIN operations, and in most database management systems (DBMSs) such JOIN operations can be costly, leading to decreased performance. The key lies in finding a balance where the first three normal forms are generally met without creating an exceedingly complicated schema.
What I'm doing is just that, I'm taking scalability into account and denormalizing the structure to accommodate better performance by requiring less quries/joins. The fact that I don't have tables: total_threads_by_forum, thread_statistical_information should be proof enough that I'm denormalizing



-------------------
Do you <3 Faith? Win a copy of Mirrors Edge!
quote   quick quote   edit   quick edit   del  report
[All dates in (PT) time]Threads List   « Next Newest   Next Oldest »
REPLY TO THIS THREAD   START A NEW THREAD


search:
Neoseeker Forums » Programming and Design » Web Coding » Building a Database



Jump to another forum:

Powered by neoforums v0.9.4 (equilibrium)
Copyright Neo Era Media, Inc. 1999-2008

neoseeker forum community
Neoseeker.com   |   Forum Rules   |   Forum FAQ   |   Neoseeker Terms of Use   |   Supermods On Duty [ server id: nova ··· elapsed: 0.0703248978]
Affiliated sites:   GameGrep - Football Manager Wiki - Halo Wiki - MGS Wiki - GTA Wiki - Smackdown Wiki - Zelda Wiki - PS2seeker - Xbox seeker - GC seeker - DEVPEN - GFXcess