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.
CREATE DATABASE database_name
SQL CREATE DATABASE Example
MySQL / SQL Server / Oracle / MS Access:
CREATE DATABASE EngineDB
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.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
)
SQL CREATE TABLE Example
This creates a table named Vehicles with five columns.
CREATE TABLE Vehicles (
VehicleID INT,
Brand VARCHAR(255),
EngineSize INT,
FuelType VARCHAR(100),
Origin VARCHAR(255)
)

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.
CREATE TABLE new_table AS
SELECT column1 column2
FROM existing_table
SQL CREATE TABLE Using Another Table Example
CREATE TABLE PopularBrands AS
SELECT Brand FuelType
FROM Vehicles

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.
CREATE INDEX index_name
ON table_name (column1 column2 ...)
SQL CREATE INDEX Example
This creates an index on the Brand column in the Vehicles table.
CREATE INDEX idx_brand
ON Vehicles (Brand)

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.
CREATE UNIQUE INDEX index_name
ON table_name (column)
SQL CREATE UNIQUE INDEX Example
This ensures that each VehicleID is unique in the table.
CREATE UNIQUE INDEX uidx_vehicleid
ON Vehicles (VehicleID)

SQL CREATE VIEW Syntax
The CREATE VIEW command defines a virtual table based on a SELECT query.
CREATE VIEW view_name AS
SELECT column1 column2
FROM table_name
WHERE condition
SQL CREATE VIEW Example
This creates a view showing only vehicles from Japan.
CREATE VIEW JapaneseVehicles AS
SELECT Brand EngineSize
FROM Vehicles
WHERE Origin = 'Japan'

SQL CREATE OR REPLACE VIEW Example
The CREATE OR REPLACE VIEW command updates an existing view with a new definition.
CREATE OR REPLACE VIEW JapaneseVehicles AS
SELECT Brand EngineSize FuelType
FROM Vehicles
WHERE Origin = 'Japan'
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.
SELECT * FROM Vehicles
SQL CREATE PROCEDURE Syntax
The CREATE PROCEDURE command creates a stored procedure. A procedure is a saved SQL block that can be executed repeatedly.
CREATE PROCEDURE procedure_name
AS
SQL statements
SQL CREATE PROCEDURE Example
CREATE PROCEDURE SelectAllVehicles
AS
SELECT * FROM Vehicles
GO
Execute procedure:
EXEC SelectAllVehicles
Note: SQLite does not support stored procedures. This feature is available only in MySQL SQL Server Oracle and similar systems.