SQL CREATE UNIQUE INDEX Keyword

CREATE UNIQUE INDEX

The CREATE UNIQUE INDEX command creates a unique index on a table (no duplicate values allowed)

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 “uidx_pid” on the “PersonID” column in the “Persons” table: Continue reading SQL CREATE UNIQUE INDEX Keyword

SQL CREATE OR REPLACE VIEW Keyword

CREATE OR REPLACE VIEW

The CREATE OR REPLACE VIEW command updates a view.

The following SQL adds the “City” column to the “Brazil Customers” view:

Example

CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = "Brazil";

Continue reading SQL CREATE OR REPLACE VIEW Keyword

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