TABLE

SQL TABLE Keyword

The TABLE keyword is used in several SQL statements such as CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE TABLE. These commands allow you to create, modify, and delete tables in a database.

SQL CREATE TABLE Syntax

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

Tutorials dojo strip

SQL CREATE TABLE Example

This query creates a new table named Rooms with four columns.

CREATE TABLE Rooms (
    room_id INTEGER,
    room_type TEXT,
    capacity INTEGER,
    floor_number INTEGER
);

SQL CREATE TABLE Using Another Table Syntax

CREATE TABLE new_table AS
SELECT column1, column2, ...
FROM existing_table;

SQL CREATE TABLE Using Another Table Example

This query creates a new table DoctorsBackup that copies data from Doctors.

CREATE TABLE DoctorsBackup AS
SELECT doctor_id, specialty
FROM Doctors;

SQL ALTER TABLE Syntax

ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name;

SQL ALTER TABLE ADD COLUMN Example

This query adds a new column room_color to the Rooms table.

ALTER TABLE Rooms
ADD room_color TEXT;

SQL ALTER TABLE DROP COLUMN Example

ALTER TABLE Rooms
DROP COLUMN room_color;

SQL DROP TABLE Syntax

DROP TABLE table_name;

SQL DROP TABLE Example

This query deletes the Rooms table.

DROP TABLE Rooms;

SQL TRUNCATE TABLE Syntax

TRUNCATE TABLE table_name;

SQL TRUNCATE TABLE Example

TRUNCATE TABLE Patients;

Note: This syntax does not work in TechKubo playground. SQLite does not support the TRUNCATE TABLE command. Use DELETE FROM table_name; instead if needed.

SQL TABLE Labs

Tutorials dojo strip
Scroll to Top