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

Learn SQL: Manipulation Cheatsheet

The document defines SQL commands for manipulating data in database tables. It describes column constraints like primary keys and default values. It also explains commands for creating tables, inserting rows, altering tables by adding columns, deleting rows that match conditions, and updating rows by setting column values.

Uploaded by

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

Learn SQL: Manipulation Cheatsheet

The document defines SQL commands for manipulating data in database tables. It describes column constraints like primary keys and default values. It also explains commands for creating tables, inserting rows, altering tables by adding columns, deleting rows that match conditions, and updating rows by setting column values.

Uploaded by

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

6/13/23, 3:16 PM

Cheatsheets / Learn SQL

Manipulation

Column Constraints
Column constraints are the rules applied to the CREATE TABLE student (
values of individual columns:
id INTEGER PRIMARY KEY,
PRIMARY KEY constraint can be used to
uniquely identify the row. name TEXT UNIQUE,
UNIQUE columns have a different value grade INTEGER NOT NULL,
for every row.
age INTEGER DEFAULT 10
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.

CREATE TABLE Statement


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

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

-- Insert into columns by name:


INSERT INTO table_name (column1,
column2)
VALUES (value1, value2);

about:srcdoc Page 1 of 2
6/13/23, 3:16 PM

ALTER TABLE Statement


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

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

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

Print Share

about:srcdoc Page 2 of 2

You might also like