If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > FOREIGN KEYs for starters

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-10, 17:56
vivoices vivoices is offline
Registered User
 
Join Date: Jul 2009
Posts: 45
FOREIGN KEYs for starters

I have a "sizes" and a "finishes" table each of which has an "available" boolean field.

A "products" table uses the "sizes" id and "finishes" id, which are primary key fields, to build products.

I would like to maintain an "available" boolean field in the "products" table as well.

Would FOREIGN KEYs be able to update the "products"."available" field as in:
Code:
UPDATE
	products
	INNER JOIN
		sizes
	ON
		sizes.sizeId = products.sizeId

	INNER JOIN
		finishes
	ON
		finishes.finishId = products.finishId
SET
	products.available = ( sizes.available AND finishes.available )
and if yes, how to set the FKs up?

Thanks for any help,
David
Reply With Quote
  #2 (permalink)  
Old 04-23-10, 19:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
alas, foreign keys won't accomplish that

you could write triggers, if you were a masochist

i would expect that you'll be happy running the update query manually as necessary, i.e. as often as you add new sizes and finishes
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-23-10, 19:40
vivoices vivoices is offline
Registered User
 
Join Date: Jul 2009
Posts: 45
Thanks for saving me some time.

It will be no problem updating manually.
New sizes and finishes are less of a problem than switching their availability on and off.
Just that the DB I am designing for the project has a lot of updating need like in the example for my question.
I will just "bundle" an UPDATE statement to every relevant point in the application.

It would have been nice to have a database that could keep data-integrity by itself.

Last edited by vivoices; 04-23-10 at 19:43.
Reply With Quote
  #4 (permalink)  
Old 04-24-10, 03:17
vivoices vivoices is offline
Registered User
 
Join Date: Jul 2009
Posts: 45
I looked into triggers, now that you mentioned them.
I learned to set them up in no time and they are exactly what I need. They are a very simple form of an event system which is the "spine" for OOP, great!

Only working in the dark would indeed be masochistic, if that is what you meant.

Can you recommend a good, perhaps even free IDE for conveniently developing and maintaining a fair amount of triggers in MySQL?
I found phpMyIDE but have not idea if it is any good.

Do you think there are other reasons to feel masochistic for working with triggers?

Thanks a lot for your input,
David
Reply With Quote
  #5 (permalink)  
Old 04-24-10, 03:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by vivoices View Post
Can you recommend a good, perhaps even free IDE for conveniently developing and maintaining a fair amount of triggers in MySQL?
HeidiSQL
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 04-24-10, 03:46
vivoices vivoices is offline
Registered User
 
Join Date: Jul 2009
Posts: 45
Thanks,
installing and checking.

Happy coding
Reply With Quote
  #7 (permalink)  
Old 04-29-10, 05:41
vivoices vivoices is offline
Registered User
 
Join Date: Jul 2009
Posts: 45
HeidiSQL is great!

Just too bad that a lot of hosting providers do not allow to connect to databases remotely in shared hosting environments.
I am still working with both phpMyAdmin and Heidi and phpMyAdmin does not include the SQL for the triggers when exporting a database to a SQL file.

Thanks again,
David
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On