0% found this document useful (0 votes)
2 views

SQL-Cheat-Sheet-Create-Table.md

This document is a SQL cheat sheet that provides syntax and descriptions for key commands such as CREATE TABLE, ALTER TABLE, TRUNCATE TABLE, and DROP TABLE. Each command includes examples to illustrate its usage. The document is authored by Himanshu Birla and includes a changelog for version updates.

Uploaded by

nam le
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL-Cheat-Sheet-Create-Table.md

This document is a SQL cheat sheet that provides syntax and descriptions for key commands such as CREATE TABLE, ALTER TABLE, TRUNCATE TABLE, and DROP TABLE. Each command includes examples to illustrate its usage. The document is authored by Himanshu Birla and includes a changelog for version updates.

Uploaded by

nam le
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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

Command Syntax Description Example

CREATE CREATE TABLE table_name (col1 datatype CREATE TABLE statement is to create the CREATE TABLE employee ( employee_id
TABLE optional keyword, col2 datatype table. Each column in the table is specified char(2) PRIMARY KEY, first_name
optional keyword,col3 datatype optional with its name, data type and an optional varchar(30) NOT NULL, mobile int);
keyword,..., coln datatype optional keyword which could be PRIMARY KEY,
keyword) NOT NULL, etc.,

ALTER ALTER TABLE table_name ADD COLUMN ALTER TABLE statement is used to add the ALTER TABLE employee ADD COLUMN income
TABLE - column_name_1 datatype....ADD COLUMN columns to a table. bigint;
ADD column_name_n datatype;
COLUMN

ALTER ALTER TABLE table_name ALTER COLUMN ALTER TABLE ALTER COLUMN statement is ALTER TABLE employee ALTER COLUMN
TABLE - column_name_1 SET DATA TYPE datatype; used to modify the data type of columns. mobile SET DATA TYPE CHAR(20);
ALTER
COLUMN

ALTER ALTER TABLE table_name DROP COLUMN ALTER TABLE DROP COLUMN statement is ALTER TABLE employee DROP COLUMN mobile
TABLE - column_name_1 ; used to remove columns from a table. ;
DROP
COLUMN

ALTER ALTER TABLE table_name RENAME COLUMN ALTER TABLE RENAME COLUMN statement is ALTER TABLE employee RENAME COLUMN
TABLE - current_column_name TO new_column_name; used to rename the columns in a table. first_name TO name ;
RENAME
COLUMN

TRUNCATE TRUNCATE TABLE table_name IMMEDIATE; TRUNCATE TABLE statement is used to TRUNCATE TABLE employee IMMEDIATE ;
TABLE delete all of the rows in a table. The
IMMEDIATE specifies to process the
statement immediately and that it cannot
be undone.

DROP DROP TABLE table_name ; Use the DROP TABLE statement to delete a DROP TABLE employee ;
TABLE table from a database. If you delete a
table that contains data, by default the
data will be deleted alongside the table.

Author(s)
Himanshu Birla

Changelog
Date Version Changed by Change Description

2021-07-27 1.0 Himanshu Birla Initial Version

You might also like