Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
I need guidance on creating branch address database
Welcome,
Guest
. Please
login
or
register
.
December 03, 2008, 11:54:52 PM
11306
Posts in
1249
Topics by
499
Members
Latest Member:
haulaslemycle
Home
Help
Search
Login
Register
Experts Round Table Network
|
Databases
|
MySQL
|
I need guidance on creating branch address database
« previous
next »
Pages:
[
1
]
Print
Author
Topic: I need guidance on creating branch address database (Read 343 times)
thepreacher
Offline
Posts: 78
I need guidance on creating branch address database
«
on:
January 10, 2007, 04:30:52 PM »
hello all this is my first post. I am working on a site where i need to allow customers to choose where they will like to receive a service. They need to select the Country, then the Region then the address. The relationship between the three is :
One
country can have
Many
Regions then
One
Region can have
Many
Addresses.
My solution is to design 2 tables. But since the number of regions a country can have is not the same for all countries i am stuck with how to design such a database. Hope i make sense.
Thnks
Logged
rdivilbiss
Governing Council Member
Offline
Posts: 414
Re: I need guidance on creating branch address database
«
Reply #1 on:
January 10, 2007, 05:34:48 PM »
It doesn't matter how many regions a county has.
Countries table
Country_Code -> primary key
Country_Name
etc.
Regions Table
Region_Code -> primary key
Country_Code -> foreign key to Countries table
Region_Name
etc.
Address table
Address_Code -> primary key
Region_Code -> foreign key to regions table
Address
etc.
If you wanted, you could add the Country_Code to the address table as well, but it isn't necessary.
That's three tables, not two. You could come up with some convoluted way to combine the countries and regions tables, but I think it will make overall maintenance more complicated.
Try to enumerate all the data access you'll need and abstract those.
You should have something like this:
MySQL
db abstraction layer (support for security and parameterized queries)
data access routines <- the access functions you enumerated
business logic (consumer of the data access routines with input/output filtering-security)
presentation layer (forms to pass users choices to the business logic.)
Regards,
Rod
Logged
Rod
VGR
Mentor
Offline
Posts: 682
Re: I need guidance on creating branch address database
«
Reply #2 on:
January 11, 2007, 01:50:49 PM »
yes. Your problem is the perfect example of the usefulness of relational database systems ;-) (RDBMS)
In fact, denormalizing the conceptual analysis above leads you to implement the relationship "belongs to" (region in country and address in region) in two ways :
- either you use foreign keys, ie "automatic" indices held by the RDBMS
- either you implement "relationship tables" on which you've full control.
the second solutions would mean you need to write the countr, regions and addresses as :
countries
id or code - primary key
rest of country's attributes (name, comment, whatever)
creationDT DATETIME
modificationDT datetime (those are nice to have)
last_modif_user_id (even better)
creator_user_id
regions
id or code - primary key
rest of region's attributes (name, comment, whatever)
idem as above for "control data"
+ relationship table country_regions :
id integer unsigned unique auto_increment (or PRIMARY KEY, it's the same)
id[or code]_country integer
id[or code]_region integer
you will thus have only ONE entry in regions for each region, ONE entry in countries for each country, and MULTIPLE (and fast & small ;-) entries in country_regions representing each occurence of a region in a country
afterwards, getting the regions of a country (let(s say "id1") is simply writing this :
select a.* from regions AS a LEFT JOIN country_regions AS b ON (b.id_country=a.id_region) WHERE b.id_country=id1;
Logged
techie overlord, answers all kind of questions on
http://www.europeanexperts.org
Pages:
[
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com