SQL Getting Sta...login
SQL Getting Started Tutorial Manual
author:php.cn  update time:2022-04-12 14:15:40

SQL syntax



Database tables

A database usually contains one or more tables. Each table is identified by a name (for example: "Websites") and contains records (rows) with data.

In this tutorial, we created the Websites table in the MySQL php database to store website records.

We can view the data of the "Websites" table through the following command:

mysql> use php;
Database changed

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM Websites;
+----+-------------+ --------------------------+-------+----------+
| id | name | url | alexa | country |
+----+-------------+---------------- -----------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | php Chinese website | //m.sbmmt.com/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+ ----+--------------+---------------------------+-- -----+---------+
5 rows in set (0.01 sec)

Analysis

  • use php; command is used to select the database.

  • set names utf8; command is used to set the character set used.

  • SELECT * FROM Websites; Read information from the data table.

  • The above table contains five records (each corresponding to a website information) and 5 columns (id, name, url, alexa and country).


SQL Statements

Most of the work you need to perform on a database is done by SQL statements.

The following SQL statement selects all records from the "Websites" table:

Example

SELECT * FROM Websites;

In this tutorial, we will teach you about different SQL statements.


Remember...

  • SQL is not case sensitive: SELECT is the same as select.


# Semicolon after SQL statement?

Some database systems require a semicolon at the end of each SQL statement.

The semicolon is the standard way to separate each SQL statement in database systems so that more than one SQL statement can be executed in the same request to the server.

In this tutorial, we will use a semicolon at the end of each SQL statement.


Some of the most important SQL commands

  • SELECT - Extract data from database

  • UPDATE - Update data in the database

  • DELETE - Delete data from the database

  • INSERT INTO - Insert new data into the database

  • CREATE DATABASE - Create a new database

  • ALTER DATABASE - Modify the database

  • CREATE TABLE - Create a new table

  • ALTER TABLE - Alter (change) the database table

  • DROP TABLE - Delete the table

  • CREATE INDEX - Create index (search key)

  • DROP INDEX - Delete index

php.cn