SQL Flashcards
What is SQL
Structured Query Language
IBM started out SQL as SEQUEL (Structured English QUEry Language) in the 1970s to query databases.
What is a database
A set of data stored in a computer
What is a relational database
A type of database that lets us store and identify data in relation to other data; often organized into tables
What are tables made of
Rows (records) and columns (which have names and data types)
What is an RDMS
Relational Database Management System; lets you create, update, and administer a relational database
Most use SQL to access the database
What is SQLite
A RDMS that uses minimal SQL
What are five popular RDMSs
MySQL, PostgreSQL, Oracle DB, SQL Server, SQLite
Where is a glossary of SQL commands
https://www.codecademy.com/articles/sql-commands
ALTER TABLE
ALTER TABLE table_name
ADD column_name datatype;
adds column to a table in a database
What are some of the most common data types in relational databases
INTEGER
TEXT
DATE YYYY-MM-DD
REAL (decimal value)
What are a statement and its components
Text a database recognizes as a valid command
clauses/commands: written in caps
table name to which the clause applies
parameter: list of columns, data types, or values that are passed into the clause as an argument
What do SELECT statements return
A table
What are constraints
add info about how a column can be used; are added after data type; tells database to reject data that does not conform
CREATE TABLE
creates a new table
INSERT INTO
adds a new row to a table
SELECT
queries data from a table
UPDATE
UPDATE table_name
SET some_column = some_value
WHERE some_column = some_value;
edits a row in a table
DELETE FROM
deletes rows from a table
what is the purpose of *
selects every column in the table
SELECT DISTINCT
SELECT DISTINCT column_name
FROM table_name;
specifies that the statement is going to be a query that returns unique values in the specified column(s).
LIKE
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
LIKE is a special operator used with the WHERE clause to search for a specific pattern in a column.
_ is wildcard
% is a wildcard character that matches zero or more missing letters in the pattern.
you can apply the LIKE operator to numerical values as well. Whenever you use LIKE however, you must always wrap the pattern within a pair of quotations, whether for matching a number or a string.
BETWEEN
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value_1 AND value_2;
The BETWEEN operator is used to filter the result set within a certain range. The values can be numbers, text or dates.
is inclusive (which works kinda differently for integers and text?)
ORDER BY
SELECT column_name
FROM table_name
ORDER BY column_name ASC | DESC;
ORDER BY is a clause that indicates you want to sort the result set by a particular column either alphabetically or numerically.
LIMIT
SELECT column_name(s)
FROM table_name
LIMIT number;
LIMIT is a clause that lets you specify the maximum number of rows the result set will have.
not supported in all SQL databases