Quote:
Originally Posted by djminus1
Would I need to create a seperate table for each user to log their bike rides?
No, that is usually not a good idea.
The typical way to create such a database would be to create one user table and one log table, like your example showed.
Then the two tables would be "connected" via a
Foreign Key column in the log table, which would reference the userid in the user table.
This is typically called a one-to-many relation (1:N), because a single row in the user table could be linked to multiple rows in the log table.
The syntax to create such a relation could look something like:
-
CREATE TABLE `User` (
-
`UserID` INT Unsigned Not Null Auto_Increment,
-
`UserName` VarChar(255) Not Null,
-
/* Etc... */
-
Primary Key (`UserID`)
-
)Engine=InnoDB;
-
-
CREATE TABLE `Log` (
-
`LogID` Int Unsigned Not Null Auto_Increment,
-
`UserID_FK` Int Unsigned Not Null,
-
`LogValue` VarChar(255) Not Null,
-
/* Etc... */
-
Primary Key (`LogID`),
-
Foreign Key (`UserID_FK`) REFERENCES `User`(`UserID`)
-
)Engine=InnoDB;
-
Note that I specify the InnoDB engine when I create the table in order to make sure that the Foreign Key constraint is enforced.
The MyISAM engine simply ignores them.