Week 7 Flashcards
What is the UNIQUE Constraint in MySQL?
Ensures values in a column or group of columns are different
What is the CHECK Constraint in MySQL?
Ensures that values stored in a column or group of columns satisfy a Boolean expression
What is the NOT NULL Constraint in MySQL?
Ensures values in a column or a group of columns are different
What is a Foreign Key (Constraint)?
Refers to Primary Key in another table
Is a column or set of columns used to establish a link between the data in two tables
These columns must match the columns in the referenced table (the parent table) and must have the same data type
What are Constraints in MySQL?
SQL Constraints are rules applied to columns in a table to ensure data integrity and consistency
They help to define the type of data that can be inserted into a table and prevent invalid data
What is a Primary Key (Constraint)?
Implicitly means NOT NULL + UNIQUE
A table can have one and only one primary key
What is SQL?
SQL is a standard language for interaction with a relational database
declarative language (focuses on the what, not how)
What is SELECT in SQL?
The SQL command used to retrieve data from a database
It specifies which columns and rows to fetch from one or more tables. Example: SELECT column1, column2 FROM table_name;
What is SELECT- DISTINCT in SQL?
The SQL command used to retrieve unique (non-duplicate) values from a column or set of columns in a table
It removes duplicate rows from the result
Example: SELECT DISTINCT column1 FROM table_name;
What is SELECT - WHERE in SQL?
The SQL command used to retrieve data from a table based on a specific condition
The WHERE clause filters the rows that meet the given condition
Example: SELECT column1 FROM table_name WHERE condition;
This returns only the rows where the condition is true
eg.
SELECT CustomerName, City, Country
FROM Customers
WHERE Country = ‘Spain’
What are the 5 basic Selection conditions in SQL?
Comparison: =, <>, (!=), <, <=, >=, >, OR, AND, NOT
Range: BETWEEN … AND, NOT BETWEEN.. AND
Set membership: IN, NOT IN
Pattern Match: LIKE, NOT LIKE
IS NULL, IS NOT NULL
What is SELECT - BETWEEN/IN
SELECT - BETWEEN/IN:
BETWEEN: Filters rows where a column value is within a specified range (inclusive).
Example: SELECT column1 FROM table_name WHERE column1 BETWEEN 10 AND 20;
IN: Filters rows where a column value matches any value in a specified list.
Example: SELECT column1 FROM table_name WHERE column1 IN (10, 20, 30);
What is SELECT - LIKE/NOT LIKE
SELECT - LIKE/NOT LIKE:
LIKE: Filters rows where a column value matches a specified pattern, often using wildcard characters (% for any sequence of characters, _ for a single character)
Example: SELECT column1 FROM table_name WHERE column1 LIKE ‘A%’; (finds values starting with “A”)
NOT LIKE: Filters rows where a column value does not match a specified pattern
Example: SELECT column1 FROM table_name WHERE column1 NOT LIKE ‘A%’; (finds values that don’t start with “A”)
What is SELECT - IS NULL/ IS NOT NULL
IS NULL: Filters rows where a column value is NULL (unknown or missing).
Example: SELECT column1 FROM table_name WHERE column1 IS NULL;
IS NOT NULL: Filters rows where a column value is not NULL (i.e., has a value).
Example: SELECT column1 FROM table_name WHERE column1 IS NOT NULL;
What is SELECT - ORDER BY
SELECT - ORDER BY: The SQL command used to sort the results of a query by one or more columns, either in ascending (ASC) or descending (DESC) order.
Example:
SELECT column1 FROM table_name ORDER BY column1 ASC; (sorts in ascending order)
SELECT column1 FROM table_name ORDER BY column1 DESC; (sorts in descending order)