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

Learn SQL - Manipulation Cheatsheet - Codecademy

The CREATE TABLE statement is used to create a new table and specify its columns and data types. The INSERT statement inserts new rows into a table, either by specifying columns in order or by name. The UPDATE statement edits existing rows by setting column values and filtering by a WHERE clause. The ALTER TABLE statement modifies existing table columns, such as adding a new column. The DELETE statement removes rows from a table using an optional WHERE clause to filter which rows. Column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT add rules for column values during table creation.

Uploaded by

ilias ahmed
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)
105 views

Learn SQL - Manipulation Cheatsheet - Codecademy

The CREATE TABLE statement is used to create a new table and specify its columns and data types. The INSERT statement inserts new rows into a table, either by specifying columns in order or by name. The UPDATE statement edits existing rows by setting column values and filtering by a WHERE clause. The ALTER TABLE statement modifies existing table columns, such as adding a new column. The DELETE statement removes rows from a table using an optional WHERE clause to filter which rows. Column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT add rules for column values during table creation.

Uploaded by

ilias ahmed
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
CREATE TABLE Statement
The CREATE TABLE statement creates a new table in a
database. It allows one to specify the name of the table CREATE TABLE table_name (
and the name of each column in the table.   column1 datatype,
  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);

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

ALTER TABLE Statement


The ALTER TABLE statement is used to modify the
columns of an existing table. When combined with the ALTER TABLE table_name
ADD COLUMN clause, it is used to add a new column. ADD column_name datatype;

DELETE Statement
The DELETE statement is used to delete records (rows) in
a table. The WHERE clause specifies which record or DELETE FROM table_name
records that should be deleted. If the WHERE clause is WHERE some_column = some_value;
omitted, all records will be deleted.
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 uniquely
  name TEXT UNIQUE,
identify the row.
  grade INTEGER NOT NULL,
● UNIQUE columns have a different value for every   age INTEGER DEFAULT 10
row. );
● NOT NULL columns must have a value.

● DEFAULT assigns a default value for the column


when no value is specified.

There can be only one PRIMARY KEY column per table


and multiple UNIQUE columns.

You might also like