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

SQL Cheat Sheet Create Table - MD

This document provides a cheat sheet on SQL commands for creating, altering, dropping, and truncating tables. It defines the CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE TABLE commands and their usage, providing the syntax and examples for each command. The ALTER TABLE command can be used to add, modify, or drop columns from a table. The DROP TABLE command deletes the entire table.

Uploaded by

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

SQL Cheat Sheet Create Table - MD

This document provides a cheat sheet on SQL commands for creating, altering, dropping, and truncating tables. It defines the CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE TABLE commands and their usage, providing the syntax and examples for each command. The ALTER TABLE command can be used to add, modify, or drop columns from a table. The DROP TABLE command deletes the entire table.

Uploaded by

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

12/7/22, 10:49 PM https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Create-Table.md.html?

origin=www…

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

Command Syntax Description Example

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

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

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

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

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

TRUNCATE TRUNCATE TABLE table_name TRUNCATE TABLE statement is used to TRUNCATE TABLE employee IMMEDIATE ;
TABLE IMMEDIATE; 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 DROP TABLE employee ;
TABLE delete a 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

https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Create-Table.md.html?origin=www.coursera.org 1/1

You might also like