Latest web development tutorials

SQL syntax

Database Table

A database typically contains one or more tables. Each table consists of a name identification (for example: "Websites"), the table contains a record with data (rows).

In this tutorial, we create a table in the MySQL Websites w3big database for storing records website.

We can view the data "Websites" list through the following command:

mysql> use w3big;
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  | 淘宝          | https://www.taobao.com/   | 13    | CN      |
| 3  | 本教程      | http://www.w3big.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
+----+--------------+---------------------------+-------+---------+
5 rows in set (0.01 sec)

Resolve

  • use w3big; command is used to select the database.
  • set names utf8; command is used to set the character set used.
  • SELECT * FROM Websites; information read data table.
  • The above table contains five records (each corresponding to a site information) and five columns (id, name, url, alexa and country).

SQL statements

Much of the work you need to do on the database by the SQL statement is completed.

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

Examples

SELECT * FROM Websites ;

In this tutorial, we will explain the various SQL statements.


please remember...

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

SQL statements behind the semicolon?

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

The semicolon is a standard method of separating each SQL statement in the database system so that you can execute more than one SQL statement 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 command

  • SELECT - extracts data from the database
  • UPDATE - updates 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 - creates a new table
  • ALTER TABLE - change (changes) a database table
  • DROP TABLE - remove a table
  • CREATE INDEX - Creating an index (search key)
  • DROP INDEX - Delete Index