Learn MySQL for Developing Web Application

Learn to build web applications with PHP and MySQL, Start your own blog, e-commerce site. In this tutorial you will learn queries of MySQL and MySQLi.

SQL Basics


What is SQL

  • SQL stands for Structured Query Language.
  • It is designed for managing data in a relational database management system (RDBMS).
  • It is pronounced as S-Q-L or sometime See-Qwell.
  • SQL is a database language, it is used for database creation, deletion, fetching rows and modifying rows etc.
  • SQL is based on relational algebra and tuple relational calculus.

All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, Postgres and SQL Server use SQL as standard database language.


SQL Commands

The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified into the following groups based on their nature −

DDL - Data Definition Language

Sr.No. Command & Description
1

CREATE

Creates a new table, a view of a table, or other object in the database.

2

ALTER

Modifies an existing database object, such as a table.

3

DROP

Deletes an entire table, a view of a table or other objects in the database.


DML - Data Manipulation Language

Sr.No. Command & Description
1

SELECT

Retrieves certain records from one or more tables.

2

INSERT

Creates a record.

3

UPDATE

Modifies records.

4

DELETE

Deletes records.


DCL - Data Control Language

Sr.No. Command & Description
1

GRANT

Gives a privilege to user.

2

REVOKE

Takes back privileges granted from user.


RDBMS

RDBMS stands for Relational Database Management System.

RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

The data in RDBMS is stored in database objects called tables. A table is a collection of related data entries and it consists of columns and rows.

Look at the "Customers" table:

See this example:

SELECT * FROM Customers;

Every table is broken up into smaller entities called fields. The fields in the Customers table consist of CustomerID, CustomerName, ContactName, Address, City and PostalCode. A field is a column in a table that is designed to maintain specific information about every record in the table.

A record, also called a row, is each individual entry that exists in a table. For example, there are 91 records in the above Customers table. A record is a horizontal entity in a table.

A column is a vertical entity in a table that contains all information associated with a specific field in a table.