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
  #1  
Old May 27th, 2002, 03:17 PM
Sungam Sungam is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 1 Sungam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Sungam
Coherent data in multiple tables

With my limited knowledge of databases, I'm finding myself in a bit of a bind here...
Best way to describe the problem is by example, I'd think, so here goes:

Say I have a site with a table for user accounts. These accounts hold the info needed for the basic site. It also holds some generic information, such as a username, a password, an e-mail address, etc.
Now I want to introduce a message board to the site, and I decide that the best solution is to use a premade one, phpBB for instance, which has its own table for user accounts.
Now, here comes to problem... I'd like users who already have an account on the main site to also have an account on the message board. Obviously, whenever users changed their information, their password for instance, on one of the two accounts, it should also be changed for the other.
This could be done through code (PHP in my case), of course, simply by having multiple INSERTs and UPDATEs - I could even add in logic checks to make sure that all the data was updated correctly. Problem is, this code would quickly become rather messy (especially when I add the third table of user accounts... say, an alliance with another site or something, to share user accounts), and I have a gut feeling that it may not be necessary.

So, basically, what I want is a database function that automatically updates several tables whenever I update information in one of them. Some voice in the back of my head is whispering "relational databases", but having only worked with MySQL I know very little about those - I'm not even sure if they could do the job.
Could anyone shed some light on if that is the solution? Or if there's a simpler/better solution? And if so, where I can read up on it? Any help would be greatly appreciated.

Reply With Quote
  #2  
Old May 27th, 2002, 07:34 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,298 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 1 h 54 m 21 sec
Reputation Power: 41
Well, it looks like you are setting yourself up for a real mess, if you are not careful.

Yes, a relational database should be involved, but you need to think carefully about structure in general. Usually, it is not a good idea to duplicate data to different tables, even if you can apply logic constraints to make sure your data stays consistent. Better to find a way to have a central repository of users, and then find a way to make each application query that table. In most relational databases, views provide a good way to accomplish this. A view is simply a query that is saved as if it is another table. Thus, you could have a central table called "users", but a view called "phpBB_users", which contains only the users and columns needed for phpBB. If you name this view the same as phpBB's normal user table, then you don't need to change a line of phpBB code. However, most relational databases still don't allow for INSERTs or UPDATEs into views, only SELECTs. (there are ways around this with triggers, which are another database mechanism, but it will take some thinking)

But, this is just the tip of the iceberg. Without at least some foundation in relational databases, and relational data theory, It would take too long to explain all the possibilities and problems here, but it would require some use of views, triggers, foreign keys, and stored procedures or SQL functions.

The short answer is yes, it can be done, but MySQL won't do it for you anytime soon (maybe eventually it will be capable of all this). So, if your applications depend on MySQL specifically, you will need to code your own workaround. If MySQL is not a requirement, you should look into PostgreSQL as a database, and spend some time reading about exactly what a relational database is. (search for books by Codd, C.J. Date, Fabian Pascal, Hugh Darwen, etc... or any of the books and book reviews at http://techdocs.postgresql.org/)
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Coherent data in multiple tables


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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