SQL is a very simple language to pick up, at least for what we are going to be doing when it comes to emu database stuff. As you learn more you will notice that it is very fluid, you can really read what you are writing out. So here we go. Real quick though, I am expecting that you already have a database set up and are running some program to manage it. I am using MySQL, but you could also use many other programs, like HeidiSQL.
1. Starting Our First Query
Building a query is very simple. We will start with something quite simple. If you are using MySQL go to the database you are using. There should be a part that says "Queries". Right click and select "New Query". Now we will start by selecting something from the database. Start your new query with 'SELECT *FROM'. This is saying that you are selecting some bit of info from some location. After 'SELECT *FROM' put the table you want to search for the info in. For us we will use 'creature_names'. Your query should now look like this:
Code:
SELECT *FROM creature_names
Now you know where you are getting your information from, now you just need to say what information you want. So after 'creature_names' put 'WHERE name = Ragnaros' This is saying you are selecting the info from creature_names where the name of the NPC is Ragnaros. Your query should look like this:
Code:
SELECT *FROM creature_names WHERE name = Ragnaros
Congratulations. You have completed your first query! Press run and you will see the query in action.
2. Updating Information In Your Database
The next step with SQL is to update information. So lets say you made an NPC and you realize you put something in there wrong. You are going to want to change that without deleting the NPC from the database and creating it again right? Thats why you need to learn how to update your information. Now all update queries start with 'UPDATE'. Simple enough right? Now we need to specify what the information is that you want to update. Lets update Ragnaros' subname. We use the SET syntax to state what we are changing, and what we are changing it to. Now lets make his subname 'Our First Update'. So our query should look like this:
Code:
UPDATE creature_names SET subname = 'Our First Update'
Now be very careful. If you run this query at this point it would make every single NPC have the subname of 'Our First Update', which I'm guessing you don't want. Now we need to specify where we want to make the subname 'Our First Update'. So we will use the WHERE syntax once more. We want Ragnaros to have the subname of 'Our First Update' so we will put
Code:
WHERE name = 'Ragnaros'
This is because we want to change the subname where the name of the NPC is Ragnaros.
Our SQL should now look like this:
Code:
UPDATE creature_names SET subname = 'Our First Update' WHERE name = 'Ragnaros'
Run the query and now in-game you should see 'Our First Update' under Ragnaros' name. You will either need to reload the database in-game using GM commands or restart for this to take effect.
More coming soon! I just want to eat before I finish the rest.