SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 10/06/2017, 08:24 PM   #31
adri1
High-roller
 
Join Date: Oct 2010
Location: Spain
Posts: 1,769
Reputation: 833
Default Respuesta: [MySQL] Table structure and foreign keys

Works for sqlite?
__________________


Super RolePlay: 149.56.102.58:7777
Super FreeRoam: 192.99.57.119:7777
www.superfreeroam.com
adri1 is offline   Reply With Quote
Old 10/06/2017, 10:02 PM   #32
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,845
Reputation: 2567
Default Re: [MySQL] Table structure and foreign keys

I don't know if SQLite actually enforces relations the way MySQL does but the theory should be all the same.
__________________
Vince is offline   Reply With Quote
Old 10/06/2017, 10:10 PM   #33
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Ottawa, Canada
Posts: 1,600
Reputation: 612
Default Re: [MySQL] Table structure and foreign keys

SQLite of samp is horribly outdated.
__________________

Howz it going?!


Gammix is offline   Reply With Quote
Old 16/07/2017, 11:14 AM   #34
Tass007
Gangsta
 
Tass007's Avatar
 
Join Date: May 2011
Location: Somewhere not near you
Posts: 669
Reputation: 30
Default Re: [MySQL] Table structure and foreign keys

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"); 
__________________
Copyright © 2016 vR Studios
Currently working with vR Studios
Copying and pasting doesn't allow you to learn the things that reading and understanding will.
Tass007 is offline   Reply With Quote
Old 18/07/2017, 09:49 PM   #35
Tass007
Gangsta
 
Tass007's Avatar
 
Join Date: May 2011
Location: Somewhere not near you
Posts: 669
Reputation: 30
Default Re: [MySQL] Table structure and foreign keys

Bump?
__________________
Copyright © 2016 vR Studios
Currently working with vR Studios
Copying and pasting doesn't allow you to learn the things that reading and understanding will.
Tass007 is offline   Reply With Quote
Old 22/07/2017, 03:48 AM   #36
Tass007
Gangsta
 
Tass007's Avatar
 
Join Date: May 2011
Location: Somewhere not near you
Posts: 669
Reputation: 30
Default Re: [MySQL] Table structure and foreign keys

Bump?
__________________
Copyright © 2016 vR Studios
Currently working with vR Studios
Copying and pasting doesn't allow you to learn the things that reading and understanding will.
Tass007 is offline   Reply With Quote
Old 22/07/2017, 04:00 AM   #37
Kaperstone
High-roller
 
Kaperstone's Avatar
 
Join Date: May 2011
Location: Home
Posts: 3,099
Reputation: 560
Default Re: [MySQL] Table structure and foreign keys

read the red marks, he already stated that this tutorial is intended for people who already have general knowledge in MySQL (who already are familiar with MySQL functions and how to work with the), this is why you're not getting answers, nor from Vince.
Its not intended to guide people through MySQL, but rather give tips&tricks on how to improve your existing knowledge.
You're simply - kinda of- showing off you ignored the first post.


Refer to this tutorial, I haven't read the tutorial, but he do guide through table creation, structure, how to modify them and manage.
http://forum.sa-mp.com/showthread.php?t=485633
__________________
Kaperstone is offline   Reply With Quote
Old 22/07/2017, 05:04 AM   #38
Tass007
Gangsta
 
Tass007's Avatar
 
Join Date: May 2011
Location: Somewhere not near you
Posts: 669
Reputation: 30
Default Re: [MySQL] Table structure and foreign keys

I think you misunderstood me. I know how to save to databases and I know MySQL functions, I'm just new to the idea of having multiple tables for the same sort of thing. I think I reworded my question wrong; I was just wanting advice on how to insert the car mod into the child board of vehicle_mods and how to load from it. Plus if this isn't the place to ask questions where do I go? Go post a topic on the scripting help board? Well...Aren't you meant to look around for a similar situation you're in or topic that you're looking for and read it and if you have any questions ask? Because if I'm not allowed to post here then I'll go make another topic on the exact same thing in the Scripting Help board.
__________________
Copyright © 2016 vR Studios
Currently working with vR Studios
Copying and pasting doesn't allow you to learn the things that reading and understanding will.
Tass007 is offline   Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Table JaKe Elite Scripting Help 5 13/11/2012 07:53 AM
MySQL: Update all values in table from another table kurta999 Scripting Help 8 23/08/2012 08:55 PM
MYSQL Table thefatshizms Scripting Help 3 31/07/2012 02:06 AM
mysql table bug juraska Scripting Help 4 15/12/2011 07:34 AM


All times are GMT. The time now is 11:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.