[Tutorial] Introduction to database (Basic)
#1

Introducing database
Author: AjaxM
Last Updated: 22/05/2016 :: 11:35 AM
Hey there,

i made a tutorial relating to MySQL & other databases (SQLite). It's NOT AT ALL pawn related but before starting off with MySQL and or SQLite, you need to know these basics and its advantages WHY we must use it. That's why i'm here for! Let's start it right now!

Wha... What's a database!?

- It's a collection of information that is organised so that it can be easily accesses, managed & updated.

In a database, we have tables! We don't have to create multiple databases but, instead, create MANY TABLES in one database. A table is made up of rows & fields (Explanation in next section).

Table

- A table (or file) is an organised collection of related data.

Record or row

A row (mainly known as a 'record') is a collection of fields (explanation in next section) relating to one person, thing or event.

Fields

A field is part of a record designed to hold a single data of a specific datatype.

There are many datatypes, which, i'll explain later.

Key field

The key field plays a very important role in our table/database.

- It's a part of a record (or row) that uniquely identifies a record from other records in the file.

There's also 'primary key' which we'll learn later.

Classification for database

- A database can also be classified as manual or computerized database.

Manual Database: It's kept in books or filling cabinet.
Computerized Database: It is electronic filling systems and are very useful in providing information at very fast speed.

We can't use manual database for SA-MP, that's why, in our case, we'll use computerized database to link the game and the database.

Advantages of computerized databases
  • Store very large number of records efficiently (they take up little space)
  • Quick & easy to find information
  • Easy to add new data and to edit or delete old data
  • Data can be searched easily
  • Data can be sorted into ascending or descending order
    |_ Can be sorted with just a piece of code (which we call 'queries' - we'll learn about it later)
  • Can be kept secure by passwording it
  • They store data in a structured way
Setting up a table name

- Database doesn't accept special character such as: ! , & , % , @ , ? , etc.....
|_ Same rule apply to field names

Example of datatype
  • Numeric - stores number only
  • Alphanumeric/Text - Stores numbers, alphabets & special characters
  • Logical - stores date & time
  • Boolean - Choose between 2 things || Eg: (Y/N) or (M/F)
Primary Key

- It's a key field that stores data. It is unique to each record in a database or a file. This prevents any records from having the same value.
|_ Eg: ID can be stored as primary key to identify them uniquely

- Primary key is also used to create a link between two or more databases or tables.

Queries

- Queries are used to get specific result from a database or a table. Query condition must be written in order to get the desired result.

To get a value from a database/table we must use the following clause:

SELECT
|_ E.g: SELECT FROM `table_name` WHERE `field_name` = 'AjaxM'

-> The following query will get the required information when the player name is "AjaxM" in the "table_name" table.

To update a player's record we should use the following clause:

UPDATE
|_ UPDATE FROM `table_name` WHERE `field_name` = 'AjaxM'

-> Self Explanatory

To delete a record from our table we should use the following clause:

DELETE
|_ DELETE FROM `table_name` WHERE `field_name` = 'AjaxM'

-> Self Explanatory

End.

That's all for today!

I'll look forward to make more tutorials on scripting MySQL or SQLite!

- Thanks,
~ AjaxM.
Reply
#2

Slight update, changed the queries.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)