0% found this document useful (0 votes)
9 views2 pages

Learn SQL - Manipulation Cheatsheet - Codecademy

This document provides a cheatsheet for SQL, detailing key commands such as CREATE TABLE, INSERT, ALTER TABLE, DELETE, and UPDATE. It explains column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT. Each command is accompanied by syntax examples for clarity.

Uploaded by

Esteban Demarchi
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)
9 views2 pages

Learn SQL - Manipulation Cheatsheet - Codecademy

This document provides a cheatsheet for SQL, detailing key commands such as CREATE TABLE, INSERT, ALTER TABLE, DELETE, and UPDATE. It explains column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT. Each command is accompanied by syntax examples for clarity.

Uploaded by

Esteban Demarchi
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/ 2

Cheatsheets / Learn SQL

Manipulation
Column Constraints
Column constraints are the rules applied to the
values of individual columns: CREATE TABLE student (
id INTEGER PRIMARY KEY,
● PRIMARY KEY constraint can be used to
name TEXT UNIQUE,
uniquely identify the row.
grade INTEGER NOT NULL,
● UNIQUE columns have a di erent value age INTEGER DEFAULT 10
for every row.
);
● NOT NULL columns must have a value.

● DEFAULT assigns a default value for the


column when no value is speci ed.

There can be only one PRIMARY KEY column


per table and multiple UNIQUE columns.

CREATE TABLE Statement


The CREATE TABLE statement creates a new
table in a database. It allows one to specify the CREATE TABLE table_name (
name of the table and the name of each column column1 datatype,
in the table. column2 datatype,
column3 datatype
);

INSERT Statement
The INSERT INTO statement is used to add a
new record (row) to a table. -- Insert into columns in order:
It has two forms as shown: INSERT INTO table_name
VALUES (value1, value2);
● Insert into columns in order.

● Insert into columns by name. -- Insert into columns by name:


INSERT INTO table_name (column1,
column2)
VALUES (value1, value2);
ALTER TABLE Statement
The ALTER TABLE statement is used to modify
the columns of an existing table. When ALTER TABLE table_name
combined with the ADD COLUMN clause, it is ADD column_name datatype;
used to add a new column.

DELETE Statement
The DELETE statement is used to delete
records (rows) in a table. The WHERE clause DELETE FROM table_name
speci es which record or records that should WHERE some_column = some_value;
be deleted. If the WHERE clause is omitted, all
records will be deleted.

UPDATE Statement
The UPDATE statement is used to edit records
(rows) in a table. It includes a SET clause that UPDATE table_name
indicates the column to edit and a WHERE SET column1 = value1, column2
clause for specifying the record(s). = value2
WHERE some_column = some_value;

You might also like