Revature SQL Flashcards
What is SQL?
SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases.
What is a relational database management system?
A Relational Database Management System (RDBMS) is a SQL database which organize data into tables with rows and columns.
What is a database?
A Database is an application that provides long term data storage and functionality to efficiently access the stored data
What are the sublanguages of SQL?
SQL sublanguages include DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).
What is cardinality?
Cardinality in data modeling refers to the number of unique values in a column or the nature of relationships between entities (e.g., one-to-one, one-to-many).
What is a candidate key?
A candidate key is an attribute, or a set of attributes, that uniquely identifies a record in a table and could serve as a primary key.
What is referential integrity?
Referential integrity ensures that foreign keys in a database remain consistent with the primary keys they reference.
What are primary keys? Foreign keys?
A primary key uniquely identifies a record in a table. A foreign key is an attribute in one table that references the primary key of another table.
What are some of the different constraints on columns?
Constraints on columns include NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, and DEFAULT.
What is an entity relation diagram?
An Entity-Relationship Diagram (ERD) is a visual representation of the relationships between entities in a database.
What are the differences between WHERE vs HAVING?
WHERE filters rows before grouping, while HAVING filters groups after grouping.
SELECT
Region,
SUM(Revenue) AS TotalRevenue
FROM
Sales
GROUP BY
Region
HAVING
SUM(Revenue) > 10000;
What are the differences between GROUP BY and ORDER BY?
GROUP BY groups rows sharing a property, while ORDER BY sorts the results of a query.
What does LIKE do?
The LIKE operator is used for pattern matching in SQL, allowing partial matches using wildcards (% for multiple characters, _ for a single character).
Query 1: Find employees whose names start with ‘J’.
SELECT
EmployeeID, Name
FROM
Employees
WHERE
Name LIKE ‘J%’;
How do I use sub queries?
Subqueries are nested queries within a main query, used to retrieve intermediate results or filter data.
EX: Greater than average
SELECT
EmployeeID, Name, Salary
FROM
Employees
WHERE
Salary > (SELECT AVG(Salary) FROM Employees);
How does BETWEEN work?
The BETWEEN operator is used to filter values within a range, inclusive of the start and end values.
What is the order of operations in an SQL statement?
FROM
Specifies the source table(s) or subqueries.
Joins between tables are resolved at this stage.
WHERE
Filters rows based on specified conditions.
Only rows that satisfy the WHERE clause condition proceed further.
GROUP BY
Groups the data into summary rows based on specified column(s).
HAVING
Filters groups (created by GROUP BY) based on conditions.
Operates on aggregated data.
SELECT
Evaluates the columns or expressions to return in the result.
Includes functions, calculations, or derived fields.
DISTINCT
Removes duplicate rows from the result set.
ORDER BY
Sorts the result set based on specified column(s) and sort order (ASC/DESC).
LIMIT / FETCH / TOP
Restricts the number of rows returned in the final result.The order of SQL operations is FROM, WHERE, GROUP BY, HAVING, ORDER BY, and SELECT.
What is the difference between an aggregate function and a scalar function?
Aggregate functions operate on sets of values and return a single result (e.g., SUM, AVG), while scalar functions operate on individual values (e.g., UPPER, ROUND).
What are examples of aggregate and scalar functions?
Examples of aggregate functions: SUM, AVG, COUNT. Examples of scalar functions: UPPER, LOWER, ABS.