30/06/2025, 17:54 about:blank
SQL Cheat Sheet: CREATE TABLE, ALTER, DROP, TRUNCATE
Command Syntax Description Example
MySQL/DB2: CREATE TABLE table_name CREATE TABLE statement is to create the table.
Each column in the table is specified with its MySQL/DB2: CREATE TABLE employee (
CREATE (col1 datatype optional keyword, col2
employee_id char(2) PRIMARY KEY,
datatype optional keyword,col3 datatype name, data type and an optional keyword
TABLE first_name varchar(30) NOT NULL, mobile
optional keyword,..., coln datatype which could be PRIMARY KEY, NOT int);
optional keyword) NULL, etc.,
MySQL/DB2:
MySQL/DB2
Option 1. ALTER TABLE table_name ADD
ALTER column_name_1 datatype....ADD COLUMN Option 1. ALTER TABLE employee ADD income
TABLE - column_name_n datatype; ALTER TABLE statement is used to add the bigint;
ADD columns to a table.
COLUMN
Option 2. ALTER TABLE table_name ADD Option 2. ALTER TABLE employee ADD COLUMN
COLUMN column_name_1 datatype....ADD income bigint;
COLUMN column_name_n datatype;
MySQL: ALTER TABLE MODIFY MODIFY
ALTER MySQL: ALTER TABLE table_name MODIFY clause is used with the ALTER TABLE MySQL: ALTER TABLE employee MODIFY
column_name_1 new_data_type; mobile CHAR(20);
TABLE - statement to modify the data type of columns.
ALTER
DB2: ALTER TABLE table_name ALTER COLUMN DB2: ALTER TABLE employee ALTER COLUMN
COLUMN column_name_1 SET DATA TYPE datatype;
Db2: ALTER TABLE ALTER COLUMN statement is mobile SET DATA TYPE CHAR(20);
used to modify the data type of columns.
ALTER
TABLE - statement is used to MySQL/DB2:
MySQL/DB2: ALTER TABLE table_name DROP ALTER TABLE DROP COLUMN
DROP COLUMN column_name_1 ; remove columns from a table. ALTER TABLE employee DROP COLUMN mobile ;
COLUMN
MySQL:ALTER TABLE table_name CHANGE MySQL: ALTER TABLE CHANGE COLUMN
ALTER COLUMN current_column_name new_column_name CHANGE COLUMN clause is used to rename MySQL: ALTER TABLE employee CHANGE
COLUMN first_name name VARCHAR(255);
TABLE - datatype [optional keywords]; the columns in a table.
RENAME DB2: ALTER TABLE employee RENAME COLUMN
COLUMN DB2: ALTER TABLE table_name RENAME COLUMN DB2: ALTER TABLE RENAME COLUMN statement is first_name TO name;
current_column_name TO new_column_name; used to rename the columns in a table.
MySQL: TRUNCATE TABLE statement is used to
delete all of the rows in a table.
TRUNCATE MySQL: TRUNCATE TABLE table_name; MySQL: TRUNCATE TABLE employee;
TABLE Db2: The IMMEDIATE specifies to process the
DB2: TRUNCATE TABLE table_name IMMEDIATE; DB2: TRUNCATE TABLE employee IMMEDIATE ;
statement immediately and that it cannot be
undone.
Use the DROP TABLE statement to delete a table
DROP from a database. If you delete a table that MySQL/DB2:
MySQL/DB2DROP TABLE table_name ;
TABLE contains data, by default the data will be DROP TABLE employee ;
deleted alongside the table.
Author(s)
Himanshu Birla
Niveditha Pandith TS
about:blank 1/1