Likes: 0
Results 1 to 8 of 8
Thread: [SQL]Tutorial.
-
27-03-10, 11:05 AM #1
[SQL]Tutorial.
Register to remove this ad////////////SQL Introduction.////////////
Although SQL is an ANSI standard, there are many different versions of the SQL language.
However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.
Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard. However, the above posted commands, are quite nice, and come in handy, when working with a WorldOfWarcraft database, for any emulator.<
Another note : Standing the other way of Lua, SQL isn't case sensitive, you should keep that in mind.
////////////The Start Of The Guide////////////
If you know this SQL commands, you're quite far.
Code:* SELECT - extracts data from a database * UPDATE - You can update your data with this commands in your database. * DELETE - You can delete unwished collumns with this command from your database. * INSERT INTO - You can insert new data in your database, with this command.
Code:* CREATE DATABASE - creates a new database * CREATE TABLE - Name says it itself. * ALTER TABLE - Alter, means modify, so you can simply modify a table with this command. * DROP TABLE - Delete a table with this command.
Your first SQL statement.
The following SQL statement will select all the records in the "Items" table:
Code:SELECT * FROM Items
SQL SELECT Syntax
Code:SELECT Name (This is the collumn name.) FROM Items (Table name.)
Code:SELECT * FROM Items (Table name.)
Code:SELECT Names,Itemid(Collumn Names) FROM Items(Table Name)
So :
Code:Select * From Items.
In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (different) values.
Code:SELECT DISTINCT column_name(s) FROM table_name
We use the following SELECT statement:
Code:SELECT DISTINCT City FROM Persons
Now, we'll move on to the next part of my personal guide.
Using the 'Where' command. When you select somthing, with the 'Where' command, you select collumns, with specified vallues.
Example.
Code:SELECT Names (Collumn name. FROM Items (Table name.) WHERE (Your specification here.)
Code:SELECT * FROM Items (Selects all collumns from the table items.) WHERE Name='Lol' (Speaks for itself.)
Code:This is correct: SELECT * FROM Items WHERE Name='Lol' This is wrong: SELECT * FROM Persons WHERE Name=Lol
The AND operator displays a record if both the first condition and the second condition is true.
The OR operator displays a record if either the first condition or the second condition is true.
So :
Code:Select * FROM Items Where Name = 'Lol' (Name, both are collumns.) AND Id ='4500' (The Itemid.)
Next, the use of the 'OR.' command :
Code:Select * FROM Items Where Name ='Lol' OR Name='Lol1'.
A:Yes you can.
On this way :
Code:SELECT * FROM ITEMS WHERE Name='Lol' AND (Itemid='4500' OR Itemid='4501')
////////////INSERTING////////////
The INSERT INTO statement is used to insert a new row in a table.
Code:INSERT INTO Items VALUES (value1, value2, value3,...)
for example.
Code:INSERT INTO Items VALUES (4500(Id),'Loller(Name)', '25484(Displayid)')
Code:INSERT INTO Persons (Id, Name) VALUES (4500, 'Loller')
Now we're going to update the collumns.
Code:UPDATE Items SET Names=Lollerlol, Itemid=4500 WHERE Names=Lol AND Itemid=45000
Deleting collumns. <3
Code:DELETE FROM Items WHERE Itemid=4500
Code:DELETE FROM Items WHERE Name='Lol' AND Name='Loller'
› See More: [SQL]Tutorial.
-
01-04-10, 12:09 PM #2
Thanks for the guide. I needed to grasp some SQL basics
Just one question please: Are indentations allowed in SQL queries?
ThanksLast edited by Synapse; 01-04-10 at 12:19 PM.
-
01-04-10, 12:34 PM #3
-
03-04-10, 03:52 AM #4
Ok, thanks for the tip.
-
18-04-10, 05:54 AM #5
Very useful. Stickied.
-
19-04-10, 01:13 AM #6
Very nice, i will use this for sure. Im sick of doing the long ways of finding scripts that already have it set up for me :P
-
04-06-10, 10:31 PM #7
This will come in quite handy. Thanks for the info.
-
30-06-10, 08:55 AM #8
Register to remove this adthanks,