SQL syntax

Database table

A database usually contains one or more tables. Each table is identified by a name (for example: “Websites”), which contains records (rows) with data.
In this tutorial, we created the Websites table in MySQL’s RUNOOB database to store site records.
We can use the following command to view the “Websites” table data:
 Mysql> use RUNOOB;
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 | rookie tutorial | http://www.runoob.com/ | 4689 | CN |
| 4 | microblogging | http://weibo.com/ | 20 | CN |
5 | Facebook | https://www.facebook.com/ | 3 | USA |
+ ---- + -------------- + --------------------------- + - ------ + --------- +
5 rows in set (0.01 sec)

Analysis

  • Use RUNOOB; command to select the database.
  • The set names utf8; command is used to set the character set used.
  • SELECT * FROM Websites; Read the data sheet information .
  • The table above contains five records (one for each site) and five columns (id, name, url, alexa, and country).

SQL statement

Most of the work you need to perform on the database is done by SQL statements.
The following SQL statement selects all records from the “Websites” table:

Examples

SELECT * FROM Websites ;
In this tutorial, we will explain the different SQL statements for you.

please remember…

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

The semicolon after the SQL statement

Some database systems require the use of semicolons at the end of each SQL statement.
The semicolon is the standard method of separating each SQL statement in the database system, so that more than one SQL statement can be executed in the same request for the server.
In this tutorial, we will use semicolons at the end of each SQL statement.

Some of the most important SQL commands

  • SELECT – Extracts data from the database
  • UPDATE – Updates the data in the database
  • DELETE – Removes data from the database
  • INSERT INTO – Inserts new data into the database
  • CREATE DATABASE – Create a new database
  • ALTER DATABASE – Modify the database
  • CREATE TABLE – Creates a new table
  • ALTER TABLE – changes (changes) the database tables
  • DROP TABLE – delete the table
  • CREATE INDEX – Create index (search key)
  • DROP INDEX – delete index

Leave a Reply

Your email address will not be published. Required fields are marked *