SQL CREATE INDEX Keyword

CREATE INDEX

The CREATE INDEX command is used to create indexes in tables (allows duplicate values).

Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries.

The following SQL creates an index named “idx_lastname” on the “LastName” column in the “Persons” table: Continue reading SQL CREATE INDEX Keyword

SQL CREATE DATABASE Keyword

CREATE DATABASE

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

The following SQL creates a database called “testDB”:

Example

CREATE DATABASE testDB;

Tip: Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES;

Continue reading SQL CREATE DATABASE Keyword

SQL CREATE Keyword

CREATE DATABASE

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

The following SQL creates a database called “testDB”:

Example

CREATE DATABASE testDB;

Tip: Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES;

Continue reading SQL CREATE Keyword

SQL CONSTRAINT Keyword

ADD CONSTRAINT

The ADD CONSTRAINT command is used to create a constraint after a table is already created.

The following SQL adds a constraint named “PK_Person” that is a PRIMARY KEY constraint on multiple columns (ID and LastName): Continue reading SQL CONSTRAINT Keyword

SQL COLUMN Keyword

ALTER COLUMN

The ALTER COLUMN command is used to change the data type of a column in a table.

The following SQL changes the data type of the column named “BirthDate” in the “Employees” table to type year: Continue reading SQL COLUMN Keyword

SQL CASE Keyword

CASE

The CASE command is used is to create different output based on conditions.

The following SQL goes through several conditions and returns a value when the specified condition is met: Continue reading SQL CASE Keyword

SQL BETWEEN Keyword

BETWEEN

The BETWEEN command is used to select values within a given range. The values can be numbers, text, or dates.

The BETWEEN command is inclusive: begin and end values are included.

The following SQL statement selects all products with a price BETWEEN 10 and 20: Continue reading SQL BETWEEN Keyword

SQL ASC Keyword

ASC

The ASC command is used to sort the data returned in ascending order.

The following SQL statement selects all the columns from the “Customers” table, sorted by the “CustomerName” column: Continue reading SQL ASC Keyword

SQL AS Keyword

AS

The AS command is used to rename a column or table with an alias.

An alias only exists for the duration of the query.

Alias for Columns

The following SQL statement creates two aliases, one for the CustomerID column and one for the CustomerName column: Continue reading SQL AS Keyword