WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL Syntax



Database table

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

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

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

mysql> use welookups;
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  | welookups          | https://www.welookups.com/| 13    | IN      |
| 3  | welookups Tutorial      | http://www.welookups.com/ | 6  | IN      |
| 4  | yahoo          | http://yahoo.com/      | 5    | IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
+----+--------------+---------------------------+-------+---------+
5 rows in set (0.01 sec)

Parse

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

SQL statement

Most of the work you need to do on the database is done in SQL statements.

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

Example

SELECT * FROM Websites;

In this tutorial, we will introduce you to various SQL statements.


Remember ...

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

SQL The semicolon after the statement?

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

A semicolon is the standard way to separate each SQL statement in a database system 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 the 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 table
  • CREATE INDEX -Create an index (search key)
  • DROP INDEX -delete index