SQL Flashcards
Database
A set of data stored in a computer and is usually structured into tables
Relational database
A type of database that uses a structure that allows us to identify and access data in relation to another piece of data in the database
Schema
The set of columns and data types for those columns that make up the table
Relational Database Management System
A program that allows you to create, update, and administer a relational database
Most use SQL as the language
Popular RDBMS
MySQL
PostgreSQL
OracleDB
SQL Server
SQLite
Each using slight variations of the core SQL language
Common data types
INTEGER (positive or negative whole number)
TEXT (text string)
DATE (YYYY-MM-DD)
REAL (decimal)
Statement
A text that the database recognizes as a valid command
Clauses / commands
Written in capital letters and perform a specific task
Parameter
A list of columns, data types, or values that are passed into a clause as an argument
SELECT
statement used to fetch data from a database
Every query will begin with SELECT
CREATE TABLE
creates a new table in a database. It allows you to specify the name of the table and the name of each column
The parameters must include each column name and data type
INSERT
used to insert new rows into a table
Must be structured as follows
INSERT INTO table name (columns to add data)
VALUES (the values to be added to the specific columns)
*
Wildcard used with SELECT that allows us to pull all columns from a table
ALTER TABLE
lets you add columns to a table in a database. Must be followed with ADD COLUMN
ALTER TABLE table name
ADD COLUMN column name data type
NULL
A special value in SQL that represents missing / unknown / blank data
UPDATE
edits a row in a table. Must be used with SET and WHERE
UPDATE table name
SET column name = new update
WHERE identifier column name = specific row
DELETE FROM
statement deletes one or more rows from a table. Must be used with WHERE
DELETE FROM table name
WHERE column name IS row identifier
Can be used with IS NULL
Constraints
Are added after specifying the data type when creating columns for a table
CREATE TABLE table name ( column name, data type, constraint)
Common constraints
PRIMARY KEY (same as unique but can only have one primary key column in a table)
UNQIUE (data entry must be unique, multiple columns can have unique constraints)
NOT NULL (data must be entered)
DEFAULT ‘text’ (if no entry provided insert a default)
Create table
CREATE TABLE ( )
Add a new row to table
INSERT INTO
VALUES
Queries data from a table
SELECT
FROM