0% found this document useful (0 votes)
4 views1 page

SQL Cheat Sheet

This document is a SQL cheat sheet that outlines commands for creating, altering, dropping, and truncating tables in SQL. It provides syntax and examples for each command, including CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE TABLE. The document also includes authorship and changelog information.

Uploaded by

xieziheng007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

SQL Cheat Sheet

This document is a SQL cheat sheet that outlines commands for creating, altering, dropping, and truncating tables in SQL. It provides syntax and examples for each command, including CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE TABLE. The document also includes authorship and changelog information.

Uploaded by

xieziheng007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

5/13/24, 1:00 AM about:blank

SQL Cheat Sheet: CREATE TABLE, ALTER, DROP, TRUNCATE


Command Syntax Description Example
CREATE TABLE table_name (col1 datatype CREATE TABLE statement is to create the table.
CREATE optional keyword, col2 datatype optional Each column in the table is specified with its CREATE TABLE employee ( employee_id
keyword,col3 datatype optional char(2) PRIMARY KEY, first_name
TABLE keyword,..., coln datatype optional name, data type and an optional keyword which varchar(30) NOT NULL, mobile int);
keyword) could be PRIMARY KEY, NOT NULL, etc.,
1. ALTER TABLE table_name ADD
ALTER TABLE column_name_1 datatype....ADD COLUMN 1. ALTER TABLE employee ADD income
column_name_n datatype; ALTER TABLE statement is used to add the bigint;
- ADD 2. ALTER TABLE table_name ADD COLUMN 2. ALTER TABLE employee ADD COLUMN income
columns to a table.
COLUMN column_name_1 datatype....ADD COLUMN bigint;
column_name_n datatype;
ALTER TABLE
ALTER TABLE table_name ALTER COLUMN ALTER TABLE ALTER COLUMN statement is used to ALTER TABLE employee ALTER COLUMN mobile
- ALTER column_name_1 SET DATA TYPE datatype; SET DATA TYPE CHAR(20);
modify the data type of columns.
COLUMN
ALTER TABLE
ALTER TABLE table_name DROP COLUMN ALTER TABLE DROP COLUMN statement is used to ALTER TABLE employee DROP COLUMN mobile ;
- DROP column_name_1 ; remove columns from a table.
COLUMN
ALTER TABLE
ALTER TABLE table_name RENAME COLUMN ALTER TABLE RENAME COLUMN statement is used ALTER TABLE employee RENAME COLUMN
- RENAME current_column_name TO new_column_name; first_name TO name ;
to rename the columns in a table.
COLUMN
TRUNCATE TABLE statement is used to delete all of
TRUNCATE TRUNCATE TABLE table_name IMMEDIATE;
the rows in a table. The IMMEDIATE specifies to TRUNCATE TABLE employee IMMEDIATE ;
TABLE process the statement immediately and that it
cannot be undone.
Use the DROP TABLE statement to delete a table
from a database. If you delete a table that contains DROP TABLE employee ;
DROP TABLE DROP TABLE table_name ;
data, by default the data will be deleted alongside
the table.

Author(s)
Himanshu Birla

Changelog
Date Version Changed by Change Description
2023-05-04 1.1 Benny Li Formatting changes made
2021-07-27 1.0 Himanshu Birla Initial Version

about:blank 1/1

You might also like