CREATE

SQL CREATE Keyword

The CREATE keyword is used in SQL to define new objects in the database such as databases tables indexes views and procedures.

SQL CREATE DATABASE Syntax

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

SQL

Tutorials dojo strip

SQL CREATE DATABASE Example

MySQL / SQL Server / Oracle / MS Access:

SQL

Note: SQLite including our TechKubo playground does not support CREATE DATABASE. Databases are created as separate files outside SQL through the system or interface.

SQL CREATE TABLE Syntax

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

SQL

SQL CREATE TABLE Example

This creates a table named Vehicles with five columns.

SQL

SQL CREATE TABLE Using Another Table Syntax

The CREATE TABLE AS statement creates a new table by copying columns and data from an existing table.

SQL

SQL CREATE TABLE Using Another Table Example

SQL

Note: This syntax will work in SQLite only if the source table and data exist. You may need to insert sample data first before seeing results.

SQL CREATE INDEX Syntax

The CREATE INDEX command is used to speed up searches on a table. Indexes can be created on one or more columns.

SQL

SQL CREATE INDEX Example

This creates an index on the Brand column in the Vehicles table.

SQL

Note: Index creation is supported in SQLite. Keep in mind that indexes make queries faster but may slow down inserts and updates.

SQL CREATE UNIQUE INDEX Syntax

The CREATE UNIQUE INDEX command creates an index that does not allow duplicate values.

SQL

SQL CREATE UNIQUE INDEX Example

This ensures that each VehicleID is unique in the table.

SQL

SQL CREATE VIEW Syntax

The CREATE VIEW command defines a virtual table based on a SELECT query.

SQL

SQL CREATE VIEW Example

This creates a view showing only vehicles from Japan.

SQL

SQL CREATE OR REPLACE VIEW Example

The CREATE OR REPLACE VIEW command updates an existing view with a new definition.

SQL

Note: This example is not supported in SQLite. SQLite supports only CREATE VIEW and requires manually dropping the view before recreating it.

SQL CREATE Query the View Example

To use a view simply query it as if it were a table.

SQL

SQL CREATE PROCEDURE Syntax

The CREATE PROCEDURE command creates a stored procedure. A procedure is a saved SQL block that can be executed repeatedly.

SQL

SQL CREATE PROCEDURE Example

SQL

Execute procedure:

SQL

Note: SQLite does not support stored procedures. This feature is available only in MySQL SQL Server Oracle and similar systems.

SQL CREATE Labs

Tutorials dojo strip