MySQL DROP TABLE Statement

The MySQL DROP TABLE Statement

The DROP TABLE statement is used to drop an existing table in a database.

Syntax

DROP TABLE table_name;

Note: Be careful before dropping a table. Deleting a table will result in loss of complete information stored in the table!

Continue reading MySQL DROP TABLE Statement

MySQL CREATE TABLE Statement

The MySQL CREATE TABLE Statement

The CREATE TABLE statement is used to create a new table in a database.

Syntax

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).

Continue reading MySQL CREATE TABLE Statement

MySQL DROP DATABASE Statement

The MySQL DROP DATABASE Statement

The DROP DATABASE statement is used to drop an existing SQL database.

Syntax

DROP DATABASE databasename;

Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored in the database!

Continue reading MySQL DROP DATABASE Statement

MySQL CREATE DATABASE Statement

The MySQL CREATE DATABASE Statement

The CREATE DATABASE statement is used to create a new SQL database.

Syntax

CREATE DATABASE databasename;

Continue reading MySQL CREATE DATABASE Statement

MySQL Operators

MySQL Arithmetic Operators

Operator Description
+ Add
Subtract
* Multiply
/ Divide
% Modulo

Continue reading MySQL Operators

MySQL Comments

MySQL Comments

Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements.

Single Line Comments

Single line comments start with --.

Any text between — and the end of the line will be ignored (will not be executed).

The following example uses a single-line comment as an explanation: Continue reading MySQL Comments

MySQL NULL Functions

MySQL IFNULL() and COALESCE() Functions

Look at the following “Products” table:

P_Id ProductName UnitPrice UnitsInStock UnitsOnOrder
1 Jarlsberg 10.45 16 15
2 Mascarpone 32.56 23
3 Gorgonzola 15.67 9 20

Suppose that the “UnitsOnOrder” column is optional, and may contain NULL values. Continue reading MySQL NULL Functions

MySQL CASE Statement

The MySQL CASE Statement

The CASE statement goes through conditions and returns a value when the first condition is met (like an if-then-else statement). So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE clause.

If there is no ELSE part and no conditions are true, it returns NULL. Continue reading MySQL CASE Statement

MySQL INSERT INTO SELECT Statement

The MySQL INSERT INTO SELECT Statement

The INSERT INTO SELECT statement copies data from one table and inserts it into another table.

The INSERT INTO SELECT statement requires that the data types in source and target tables matches.

Note: The existing records in the target table are unaffected. Continue reading MySQL INSERT INTO SELECT Statement

MySQL ANY and ALL Operators

The MySQL ANY and ALL Operators

The ANY and ALL operators allow you to perform a comparison between a single column value and a range of other values.

The ANY Operator

The ANY operator:

  • returns a boolean value as a result
  • returns TRUE if ANY of the subquery values meet the condition

ANY means that the condition will be true if the operation is true for any of the values in the range. Continue reading MySQL ANY and ALL Operators