[Tutorial] [MySQL] Table structure and foreign keys
#32

I am quite new to understanding the way mysql works as a whole. Especially Table structure and foreign keys, I've got a system with basically the exact same system as your explanation. However I'm not sure how to add to the table and also how to load from the table. Could someone please explain and show me how to do it? Thank you

PHP Code:
mysql_format(ServerMySQL,string,sizeof(string),"CREATE TABLE IF NOT EXISTS `Vehicles` (\
        `uID` int(11) NOT NULL,\
        `VehID` int(11) unsigned NOT NULL AUTO_INCREMENT,\
        `Type` tinyint(7) NOT NULL DEFAULT '0',\ 
        `Model`  tinyint(7) NOT NULL DEFAULT '0',\
        `Locked` tinyint(7) NOT NULL DEFAULT '0',\
        `Fuel` tinyint(7) NOT NULL DEFAULT '0',\
        `CarX` float NOT NULL,\
        `CarY` float NOT NULL,\
        `CarZ` float NOT NULL,\
        `CarR` float NOT NULL,\
        `VehNum` char(9) NOT NULL,"
);
        
mysql_format(ServerMySQL,string,sizeof(string),"%s\
        `SavedWeaps0` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedAmmos0` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedWeaps1` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedAmmos1` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedWeaps2` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedAmmos2` tinyint(7) NOT NULL DEFAULT '0',"
,string);
        
mysql_format(ServerMySQL,string,sizeof(string),"%s\
        `SavedWeaps3` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedAmmos3` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedWeaps4` tinyint(7) NOT NULL DEFAULT '0',\
        `SavedAmmos4` tinyint(7) NOT NULL DEFAULT '0',\
        PRIMARY KEY (`VehID`)) ENGINE = InnoDB DEFAULT CHARSET=latin1"
,string);
        
mysql_tquery(ServerMySQLstring);
        
mysql_tquery(ServerMySQL"ALTER TABLE `Vehicles` ADD FOREIGN KEY (`uID`) REFERENCES `Users` (`uID`) ON UPDATE CASCADE ON DELETE CASCADE");
        
mysql_format(ServerMySQL,"CREATE TABLE IF NOT EXISTS `Vehicle_Mods` (\
        `VehID` int(11) unsigned NOT NULL,\
        `mod_model` smallint(5) unsigned NOT NULL,\
        `Col1` tinyint(7) unsigned NOT NULL DEFAULT '0',\
        `Col2` tinyint(7) unsigned NOT NULL DEFAULT '0',\
        `CarPaint` smallint(7) unsigned NOT NULL DEFAULT '255',\
        PRIMARY KEY (`VehID`, `mod_model`)) ENGINE = InnoDB DEFAULT CHARSET=latin1"
);
        
mysql_tquery(ServerMySQLstring);
        
mysql_tquery(ServerMySQL"ALTER TABLE `Vehicle_Mods` ADD FOREIGN KEY (`VehID`) REFERENCES `Vehicles` (`VehID`) ON UPDATE CASCADE ON DELETE CASCADE"); 
Reply


Messages In This Thread
[MySQL] Table structure and foreign keys - by Vince - 04.03.2013, 17:19
Re: [MySQL] Table structure and foreign keys - by Misiur - 04.03.2013, 17:35
Re: [MySQL] Table structure and foreign keys - by Kyle - 04.03.2013, 18:00
Re: [MySQL] Table structure and foreign keys - by Scenario - 04.03.2013, 19:26
Re: [MySQL] Table structure and foreign keys - by nGen.SoNNy - 05.03.2013, 19:00
Re: [MySQL] Table structure and foreign keys - by Stylock - 06.03.2013, 12:48
Re: [MySQL] Table structure and foreign keys - by Sinner - 06.03.2013, 13:05
Re: [MySQL] Table structure and foreign keys - by Yves - 06.03.2013, 13:08
Re: [MySQL] Table structure and foreign keys - by Bluec0de - 06.03.2013, 16:31
Re: [MySQL] Table structure and foreign keys - by Stylock - 06.03.2013, 16:32
Re: [MySQL] Table structure and foreign keys - by Luis- - 09.03.2013, 12:56
Re: [MySQL] Table structure and foreign keys - by AndreT - 09.03.2013, 15:16
Re: [MySQL] Table structure and foreign keys - by Kyle - 20.03.2013, 08:27
Re: [MySQL] Table structure and foreign keys - by Michael@Belgium - 20.03.2013, 09:11
Re: [MySQL] Table structure and foreign keys - by Kar - 12.04.2013, 02:51
Re: [MySQL] Table structure and foreign keys - by Vince - 12.04.2013, 05:36
Re: [MySQL] Table structure and foreign keys - by MP2 - 12.04.2013, 06:22
Re: [MySQL] Table structure and foreign keys - by Jay_ - 14.04.2013, 12:45
Re: [MySQL] Table structure and foreign keys - by dusk - 24.07.2013, 15:55
Re: [MySQL] Table structure and foreign keys - by Sinner - 24.07.2013, 21:31
Re: [MySQL] Table structure and foreign keys - by DarrenReeder - 24.07.2013, 23:20
Re: [MySQL] Table structure and foreign keys - by Sinner - 25.07.2013, 10:04
AW: [MySQL] Table structure and foreign keys - by Mellnik - 15.04.2014, 15:42
Re: [MySQL] Table structure and foreign keys - by gotwarzone - 19.04.2014, 10:09
Re: [MySQL] Table structure and foreign keys - by Vince - 26.08.2015, 10:47
Re: [MySQL] Table structure and foreign keys - by Evocator - 19.10.2015, 17:27
Re: [MySQL] Table structure and foreign keys - by nGen.SoNNy - 22.10.2015, 08:34
Re: [MySQL] Table structure and foreign keys - by knuckleduster5 - 10.12.2016, 09:46
Respuesta: [MySQL] Table structure and foreign keys - by adri1 - 10.06.2017, 20:24
Re: [MySQL] Table structure and foreign keys - by Vince - 10.06.2017, 22:02
Re: [MySQL] Table structure and foreign keys - by Gammix - 10.06.2017, 22:10
Re: [MySQL] Table structure and foreign keys - by Tass007 - 16.07.2017, 11:14
Re: [MySQL] Table structure and foreign keys - by Tass007 - 18.07.2017, 21:49
Re: [MySQL] Table structure and foreign keys - by Tass007 - 22.07.2017, 03:48
Re: [MySQL] Table structure and foreign keys - by Kaperstone - 22.07.2017, 04:00
Re: [MySQL] Table structure and foreign keys - by Tass007 - 22.07.2017, 05:04
Re: [MySQL] Table structure and foreign keys - by Kaperstone - 22.07.2017, 16:25
Re: [MySQL] Table structure and foreign keys - by Tass007 - 22.07.2017, 19:30
Re: [MySQL] Table structure and foreign keys - by Banditul18 - 18.10.2017, 13:50

Forum Jump:


Users browsing this thread: 17 Guest(s)