Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old January 30th, 2003, 06:25 AM
RyanA RyanA is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 23 RyanA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Structure question - which method is better for storing changing fields

Lets say we have a set of tables setup to keep track of what cars a person has but the person can only enter car types that are predefined from a check box:

PHP Code:
 CREATE TABLE car (id int(6NOT NULL default '0',
                  
name varchar(255NOT NULL default '');
CREATE TABLE user (id int(6NOT NULL default '0',
                   
name varchar(255NOT NULL default '');
CREATE TABLE owned (id int(6NOT NULL default '0',
                    
car_id int(6NOT NULL default '0',
                    
user_id int(6NOT NULL default '0'); 


Would it be better to create it as..

PHP Code:
 CREATE TABLE user (id int(6NOT NULL default '0',
                   
name varchar(255NOT NULL default '');
CREATE TABLE car (user_id NOT NULL default '0',
                  
$car_name varchar(255) default NULL,
                  
$car_name varchar(255) default NULL,
                  
$car_name varchar(255) default NULL); 


.. and add new default NULL fields to the table as more cars are added? I began with the first method, but I'm leaning more twards the second now for simplicity's sake.

What are the reasons that I might want to avoid one method and use the other?

Is there a better method?

Last edited by RyanA : January 30th, 2003 at 06:29 AM.

Reply With Quote
  #2  
Old January 30th, 2003, 07:35 AM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Separating each unrelated entity is the best method and will move you toward normalization of your data.
...
The first method will allow you to change a car independently without having to modify a user. It will also allow you to define cars even before they are owned by a person.
...
Your second method closely resembles a flat file. This type of file is 'good' for searching but can very quickly become inefficient for updates and inserts.
__________________
El éxito consiste en una serie de pequeñas victorias día a día

MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html

Reply With Quote
  #3  
Old January 30th, 2003, 10:29 AM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 57 sec
Reputation Power: 12
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
Go with the first way. The second way violates the first rule of data normalization.

Check out here for more info regarding data normalization.
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Structure question - which method is better for storing changing fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway