SQL Statements

SQL Statements

SQL is almost like simple English. It is made up largely of English words, put together into strings of words that sound similar to English sentences.

The first word of each statement is its name, which is an action word (verb) that tells MySQL what you want to do. For example, CREATE, DROP, ALTER, SHOW, INSERT, LOAD, SELECT, UPDATE, and DELETE.

The statement name is followed by words and phrases that tell MySQL how to perform the action. For example,

SELECT lastName FROM Member

When a statement uses SELECT, it’s known as a query, because you are querying the database for information. This query retrieves all the last names stored in the table named Member.

Most Important SQL Statements

  1. SELECT - extracts data from a database
  2. UPDATE - updates data in a database
  3. DELETE - deletes data from a database
  4. INSERT INTO - inserts new data into a database
  5. CREATE DATABASE - creates a new database
  6. ALTER DATABASE - modifies a database
  7. CREATE TABLE - creates a new table
  8. ALTER TABLE - modifies a table
  9. DROP TABLE - deletes a table
  10. CREATE INDEX - creates an index (search key)
  11. DROP INDEX - deletes an index

There are two parts of SQL. The Data Definition Language (DDL) is the part of SQL that you use to create a database and all its tables. It also includes to modify the structure of an existing database or destroy it after you no longer need it.

The Data Manipulation Language (DML) is the part of SQL that operates on the data that inhabits that structure. There are four things that you want to do with data:

  1. Store the data in a structured way that makes it easily retrievable. (INSERT)
  2. Change the data that is stored. (UPDATE)
  3. Selectively retrieve information that responds to a need that you currently have. (SELECT)
  4. Remove data from the database that is no longer needed. (DELETE)