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

Intro To SQL - Intro To SQL Cheatsheet - Codecademy

This document provides an introduction to SQL, covering key statements such as CREATE TABLE, INSERT, ALTER TABLE, DELETE, and UPDATE. It explains column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT, as well as the syntax for each SQL statement. The document serves as a cheatsheet for basic SQL operations and their functionalities.
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)
24 views2 pages

Intro To SQL - Intro To SQL Cheatsheet - Codecademy

This document provides an introduction to SQL, covering key statements such as CREATE TABLE, INSERT, ALTER TABLE, DELETE, and UPDATE. It explains column constraints like PRIMARY KEY, UNIQUE, NOT NULL, and DEFAULT, as well as the syntax for each SQL statement. The document serves as a cheatsheet for basic SQL operations and their functionalities.
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

Cheatsheets / Intro to SQL

Intro to SQL

Column Constraints

Column constraints are the rules applied to the values CREATE TABLE student (
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 for grade INTEGER NOT NULL,
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 table CREATE TABLE table_name (
in a database. It allows one to specify the name of the
column1 datatype,
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 new -- Insert into columns in order:
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);
ALTER TABLE Statement

The ALTER TABLE statement is used to modify the ALTER TABLE table_name
columns of an existing table. When combined with the
ADD column_name datatype;
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 which
WHERE some_column = some_value;
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 (rows) UPDATE table_name


in a table. It includes a SET clause that indicates the
SET column1 = value1, column2 = value2
column to edit and a WHERE clause for specifying the
record(s). WHERE some_column = some_value;

Print Share

You might also like