So I’m futzing around seeing to what extent I can get a handle on MySQL from a manual (Vaswani’s How to do Everything with PHP & MySQL) as recommended by Lobsang in this thread, and drawing upon my own FileMaker experience.
I selected a vintage-1996 FileMaker db, my first serious FmPro db in fact, figuring it was “real world” (at one time) and yet pretty simple compared to stuff I’ve done since then…
I am now officially confused, folks. And I do not like it when I don’t understand things. I do not like feeling stupid.
This manual sort of skips over how the heck you SET UP A FREAKING RELATIONSHIP, which is odd because it provides specific walk-thrus and example command-line syntax for the creation of databases, creation of table, and defining of fields. But of relationships it sort of glosses past, explaining only “this is how you define a field as your primary key” and then mentioning that this will be used in conjunction with foreign keys, e.g.,
(p 152)
- Gee, Ya THINK!??:smack:
(p. 170)
Yeah yeah yadda yadda… so where the hell is the syntax for create relationship, dammit?
The example given makes it sound like simply by creating some fields in different tables that happen to have the same field names, some magic occurs presto connecto wowzy woo woo, suddenly there’s a relationship here!?
Why isn’t there any walk-thru?
OK, if you were Mr. Vikram Vaswani, I would want to be asking you to explain the following:
a) Let’s say I have TableOne which has a defined primary key field “employeeserial” an integer field not null and auto incrementing; and I have TableTwo which consists of records each of which will be associated with one and only one record from TableOne. I know what I’d do in FileMaker, I’d define a field in TableTwo, let’s say it’s also called “employeeserial” and it’s just a plain ol’ number field (we FileMaker folks do not have to wave any flags and say THAT THERE is a FOREIGN KEY; I gather that in MySQL I would do so, though?) and then define a relationship between the two like so:
TableOne::employeeserial = TableTwo::employeeserial
OK walk me through how I do that part in MySQL please? Just saying “Yo, you there, you’re a freaking FOREIGN KEY” doesn’t tell it what field in what table it is supposed to hook up with, right? I mean how the heck could it? Especially since… well let’s just continue…
b) For kicks, let’s assume that there exists a field in TableTwo called “status”, varchar (16) which you’d do in FileMaker simply by creating a text field “Status”; and this field may contain several different text values one of which is “Inactive”; and that I wish to establish a second relationship between TableOne and TableTwo, such that employeeserial in TableOne equals employeeserial in TableTwo AND the field status in TableTwo does NOT equal “Inactive”. I can do that in several easy ways in FileMaker: I can create a calcfield in TableTwo of result type “number” defined as Case (Status≠"Inactive", employeeserial) and then define my new relationship like so:
TableOne::employeeserial = TableTwo::newcalcfield
OR, instead I can define a calcfield in TableOne result type “text” defined simply as the constant “Inactive” and then define my relationship this way instead:
TableOne::employeeserial = TableTwo::employeeserial AND
TableOne::inactiveconstant ≠ TableTwo::status
(in modern FileMaker that would result in a second table occurrence of TableTwo on the relationship graph)
OK walk me through how I create a second relationship between two already-related tables in MySQL? I guess if I knew how to explicitly create the FIRST relationship I’d know this as well?
c) Also of interest, the selfjoin relationship, if you don’t mind. If I wish that all records in TableTwo that share the same status field value be related to each other, how do I tell MySQL to relate the table to itself in that fashion? In FileMaker, I’d make a rel between TableTwo::status and itself, which would once again prompt a new table occurrence which I’d give some useful name like TableTwoSameStatus.