close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

database structures and foreign keys

Thread began 8/03/2009 8:17 am by jenkolaka19379118 | Last modified 8/07/2009 4:54 pm by Jason Byrnes | 4103 views | 7 replies |

jenkolaka19379118

database structures and foreign keys

I am just learning mysql at the moment. I am using your Blue_Sky_music database to help me understand how relational databases work, in order to create one myself accurately. The only question I have is, looking at the bsm database using mysql gui tools and php admin, it does not appear that the tables are joined (have foriegn keys that link the tables) within them. However the data does appear to be related. Do you make the relationships in the end user application, in mysql or both? This is a question that has stumped me and I cannot seem to find a clear anwser on the web.

Sign in to reply to this post

Jason ByrnesWebAssist

In the Blue Sky Music sample database, there are a few relations in place:
Items.ItemcatID is a forign key relation to itemcategory.ItemcatID

orderdetails.DetailOrderID is a foreign key relation to orders.OrderID

orders.OrderStatus is a foreign key relation to orderstatustypes.StatusID

visitors.VisitorGroupID is a foreign key relation to groups.GroupID


making the foreign key relation in the MySQL database allows you to force referential integrity. This means that you would not be able to delete a child record with out first deleting the parent.

Sign in to reply to this post

jenkolaka19379118

Hi Jason,

Would you be able to tell me how you related the table fields (assigned foreign keys) using mysql gui tools or phpmyadmin e.g.

Items.ItemcatID is a forign key relation to itemcategory.ItemcatID

Your help is much appreciated

Sign in to reply to this post

Jason ByrnesWebAssist

We did not create the relationship in the actual database using either the mysql gui tools or phpmyadmin.


The Relationships are used in the application.
You can see some examples how the relationships are used and created by looking in the section of the eCart getting started guide that deals with storing the order information in the database usiong the Sore order Summary and Store order Details behaviors.

Also the "User Level Authentication" tutorial on the Solution recipe tab and the "How to create an Order History page" on the how to tab of the security assist support page will demonstrate how the relationships are used.


In a lot of cases, foreign key relationships are more conceptual, and are not created within the database but used by the application.


You only create the foreign relationship in the database if you want to force referential integrity.

Sign in to reply to this post

jenkolaka19379118

Thanks Jason,

I always thought you had to create relationships in mysql and in the application. Thanks for clarifying this issue for me as it has confused me for a while. The reason it confused me is because when you look at the same database in microsoft access (relational data view) it shows you the table relationships are already established (the ones you described in your first post). However in mysql there is no ui that shows you the relational data.

Sign in to reply to this post

Jason ByrnesWebAssist

in Access you have to define those relationships manually if you want to force referential integrity.

You don't have to go to the relational view and create the relationships in access, but you can.

Same with MySQL. You don't have to create the foreign key relationships, but if you want to force referential integrity, you can.

Sign in to reply to this post

jenkolaka19379118

I have been resesarching this issue and realised that you cannot force referential integrity using a myisam database engine. Unfortunately I am using a myisam database engine. Did you use a innodb database engine to create the blue sky music database?. If not how did you (do you) force referential integrity using a myisam engine?

Secondly did you need to force referential integrity on any of the relationships in the blue sky music database?

Items.ItemcatID is a forign key relation to itemcategory.ItemcatID

orderdetails.DetailOrderID is a foreign key relation to orders.OrderID

orders.OrderStatus is a foreign key relation to orderstatustypes.StatusID

visitors.VisitorGroupID is a foreign key relation to groups.GroupID



If so could you please describe to me in detail how you do it? (sql statement)

Sign in to reply to this post

Jason ByrnesWebAssist

We use the innodb database engine.

The blue sky music database is not configured to force referential integrity.


I was only referring to referential integrity because that is the only real benefit to defining the relationship in the database.

using the myisam database engine, that benefit is lost.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...