If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Database design question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-04, 04:13
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Database design question

Hi,

I need to store questions for two different subjects for three different levels (4, 5, 6). I'll most likely have separate tables for each subject.

However for each subject, I'm wondering if I should (1) create a table for each of the three levels or if should I (2) create a single table all the levels.

With option (1), I'll have two tables (english, math) with the level information stored in one of the columns.

With option (2), I'll have six tables (english4, english5, english6, math4, math5, math6) without the level information (since the table itself already holds the level information).

Which of the two options is the normal way to store data?

P.S: The database is intended for web-based application.

I hope the question is clear...

Thanks in anticipation

Last edited by pearl2; 09-09-04 at 04:33.
Reply With Quote
  #2 (permalink)  
Old 09-09-04, 04:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by pearl2
Which of the two options is the normal way to store data?
depends on whether you mean normal as in what is most common, what most people do, or normal as in normalized according to the rules of database design

i would put everything into one table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-09-04, 04:32
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Quote:
Originally Posted by r937
depends on whether you mean normal as in what is most common, what most people do, or normal as in normalized according to the rules of database design

i would put everything into one table
Thanks, r937!

Normal as in what's the most common way of doing it.

Added: What are the merits of putting everything in one table?

Last edited by pearl2; 09-09-04 at 04:36.
Reply With Quote
  #4 (permalink)  
Old 09-09-04, 04:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by pearl2
What are the merits of putting everything in one table?
all your queries are a lot simpler
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-09-04, 04:48
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
I see.

I've some concerns:

1) Are there problems with concurrent access to the same table?

2) In the event of table corruption, everything in that single table is affected. Is this an issue at all?

Thanks again and cheers
Reply With Quote
  #6 (permalink)  
Old 09-09-04, 05:39
aadaileh aadaileh is offline
Registered User
 
Join Date: Sep 2004
Posts: 2
I am not sure if I got correctly what you mean. But anyway I would suggest the following structure (You may need to modify the structure a little bit to let fit to your needs).

#
# Table structure for table `level`
#

CREATE TABLE `level` (
`id` int(11) NOT NULL default '0',
`level` varchar(10) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) TYPE=MyISAM;


#
# Dumping data for table `level`
#

INSERT INTO `level` (`id`, `level`) VALUES (0, '5');
INSERT INTO `level` (`id`, `level`) VALUES (1, '6');
INSERT INTO `level` (`id`, `level`) VALUES (2, '4');
INSERT INTO `level` (`id`, `level`) VALUES (3, '6');

# --------------------------------------------------------

#
# Table structure for table `questions`
#

CREATE TABLE `questions` (
`id` int(11) NOT NULL default '0',
`english` varchar(255) NOT NULL default '',
`math` varchar(255) NOT NULL default '',
`level_id` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) TYPE=MyISAM;

#
# Dumping data for table `questions`
#

INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (0, 'English1', '', 0);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (1, 'English 2', '', 1);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (2, 'Englsih 17', '', 2);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (3, '', 'Math 80', 3);

Ahmed
Reply With Quote
  #7 (permalink)  
Old 09-09-04, 06:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by pearl2
1) Are there problems with concurrent access to the same table?
no, no more so than if there were many tables

Quote:
2) In the event of table corruption, everything in that single table is affected. Is this an issue at all?
no, no more so than if there were many tables

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 09-09-04, 07:33
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Wonderful, great thanks r937!
Reply With Quote
  #9 (permalink)  
Old 09-09-04, 07:34
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
Quote:
Originally Posted by aadaileh
I am not sure if I got correctly what you mean. But anyway I would suggest the following structure (You may need to modify the structure a little bit to let fit to your needs).

#
# Table structure for table `level`
#

CREATE TABLE `level` (
`id` int(11) NOT NULL default '0',
`level` varchar(10) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) TYPE=MyISAM;


#
# Dumping data for table `level`
#

INSERT INTO `level` (`id`, `level`) VALUES (0, '5');
INSERT INTO `level` (`id`, `level`) VALUES (1, '6');
INSERT INTO `level` (`id`, `level`) VALUES (2, '4');
INSERT INTO `level` (`id`, `level`) VALUES (3, '6');

# --------------------------------------------------------

#
# Table structure for table `questions`
#

CREATE TABLE `questions` (
`id` int(11) NOT NULL default '0',
`english` varchar(255) NOT NULL default '',
`math` varchar(255) NOT NULL default '',
`level_id` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) TYPE=MyISAM;

#
# Dumping data for table `questions`
#

INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (0, 'English1', '', 0);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (1, 'English 2', '', 1);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (2, 'Englsih 17', '', 2);
INSERT INTO `questions` (`id`, `english`, `math`, `level_id`) VALUES (3, '', 'Math 80', 3);

Ahmed
Thanks, Ahmed! Will use it for reference.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On