2b5e Delegate Question - defining MySQL table relationships as you create the tables
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Delegate Question - defining MySQL table relationships as you create the tables

Q - Can define how tables are linked (joined together) when you set them up in MySQL, rather than having to specify the join each time that you SELECT data from the tables?

What a great (and logical) idea, but it's not straightforward / automatically available. The current / default system in the basic MySQL is somewhat illogical, as what can join up to what really ought to be specified with the database definition, and not as the data is extracted ... where erroneous (and silly) joins can be specified, and furthermore the user of the data needs to understand its structure.

There are some tools / approaches which can help towards implementing a system - basically, you want to be able to specify the orange bits in the following when calling up data, and have the magenta bit always / automatically provided from design time:

Select f1, f2, f3, f4 from t1 left join t2 on f2 = f6 where f7 > 1000

Some things that may help:

Views - From release 5.0, MySQL has included views which allow you to define a VIEW onto your data, and such views may include JOINs (gets a bit tricky at UPDATE time); a joined view - especially in conjunction with Stored Procedures - will help towards your goal.

Stored Procedures - Again, from Release 5.0. You don't need to specify the full series of MySQL statements every time, but can store them to be run each time you press the "Green Button" to make a request. [stored procedure resources]

Frameworks such as Ruby on Rails - The "Model" element of frameworks such as Ruby on Rails (and others too) allow / encourage you to specify rather more details that you would normally present to MySQL, including the limits that need to be applied to data in certain fields, and relationships. [Ruby on Rails sample]

Encapsulation of data within objects - If you access your data / database through objects, you'll be getting the ability to encapsulate the JOIN so that it won't be visible to / the concern of the user of your class of objects

Libraries of valid joins - I've found it very useful to hold libraries of valid joins in certain applications, so that only sensible joins are performed. A single composite join if you have a lot of tables (one of our customer joined 27 tables!) can be inefficient - but a menu scheme which only allows things which have been predefined can work wonders. Table of allowed joins described fully [here] and available for you to try [here]


(written 2010-05-02) 20a9

 
Associated topics are indexed under
Q916 - Object Orientation and General technical topics - Database design principles
  [918] Databases needn't be frightening, hard or expensive - (2006-11-08)
  [666] Database design - get it right from first principles - (2006-04-02)
  [572] Giving the researcher power over database analysis - (2006-01-22)
  [375] Oops - I got my initial database design wrong - (2005-07-12)

S163 - Stored Procedures in MySQL
  [2447] MySQL stored procedures / their use on the web from PHP - (2009-10-10)
  [2446] Learn about MySQL stored procedures - (2009-10-09)

S154 - MySQL - Designing an SQL Database System
  [3494] Databases - when to treat the rules as guidelines - (2011-10-23)
  [3361] Blowing our own trumpet - MySQL resources - (2011-07-18)
  [3270] SQL - Data v Metadata, and the various stages of data selection - (2011-04-29)
  [2204] Images in a database? How big is a database? (MySQL) - (2009-05-28)
  [2085] MySQL - licensing issues, even with using the name - (2009-03-16)
  [2053] What a difference a MySQL Index made - (2009-02-25)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1575] Database design for a shopping application (MySQL) - (2008-03-15)
  [1423] MySQL - table design and initial testing example - (2007-11-06)
  [945] Code quality counts - (2006-11-26)
  [937] Display an image from a MySQL database in a web page via PHP - (2006-11-22)
  [515] MySQL - an FAQ - (2005-12-03)
  [494] MySQL - a score of things to remember - (2005-11-12)
  [361] Binary Large Objects or bars - (2005-06-27)
  [59] MySQL - Pivot tables - (2004-09-22)


Back to
Monitoring the success and traffic of your web site
Previous and next
or
Horse's mouth home
Forward to
Views of Wessex
Some other Articles
You do not just fly - that is just part of the journey
Voting day - UK General Election
Going off at a tangent, for a ramble
Views of Wessex
Delegate Question - defining MySQL table relationships as you create the tables
Monitoring the success and traffic of your web site
Containment, Associative Objects, Inheritance, packages and modules
Model - View - Controller demo, Sqlite - Python 3 - Qt4
Connecting Python to sqlite and MySQL databases
PyQt (Python and Qt) and wxPython - GUI comparison
4088 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82 at 50 posts per page

3ebe
This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2749_Del ... ables.html • PAGE BUILT: Sat Feb 23 12:39:13 2013 • BUILD SYSTEM: wizard
0