Revature SQL Flashcards

1
Q

What is SQL?

A

SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a relational database management system?

A

A Relational Database Management System (RDBMS) is a SQL database which organize data into tables with rows and columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a database?

A

A Database is an application that provides long term data storage and functionality to efficiently access the stored data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the sublanguages of SQL?

A

SQL sublanguages include DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is cardinality?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a candidate key?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is referential integrity?

A

Referential integrity ensures that foreign keys in a database remain consistent with the primary keys they reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are primary keys? Foreign keys?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some of the different constraints on columns?

A

Constraints on columns include NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, and DEFAULT.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an entity relation diagram?

A

An Entity-Relationship Diagram (ERD) is a visual representation of the relationships between entities in a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the differences between WHERE vs HAVING?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the differences between GROUP BY and ORDER BY?

A

GROUP BY groups rows sharing a property, while ORDER BY sorts the results of a query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does LIKE do?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do I use sub queries?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does BETWEEN work?

A

The BETWEEN operator is used to filter values within a range, inclusive of the start and end values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the order of operations in an SQL statement?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the difference between an aggregate function and a scalar function?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are examples of aggregate and scalar functions?

A

Examples of aggregate functions: SUM, AVG, COUNT. Examples of scalar functions: UPPER, LOWER, ABS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the different joins in SQL?

A

SQL joins include INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, and CROSS JOIN.

20
Q

What are the different set operations in SQL? Which set operations support duplicates?

A

Set operations are used to join the result of two or more quieries.
UNION, INTERSECT, UNION ALL.

UNION ALL supports duplicates.

21
Q

What is the difference between joins and set operations?

A

Joins combine data from multiple tables based on conditions, while set operations combine results of multiple queries.

22
Q

How can I create an alias in SQL?

A

An alias is created using the AS keyword to provide a temporary name for a table or column.

23
Q

What does the AS keyword do in a query?

A

The AS keyword is used to create aliases for tables or columns for readability or convenience.

24
Q

What is a transaction?

A

A transaction is an interaction with a database

25
Q

What are the properties of a transaction?

A

Transactions have ACID properties: Atomicity, Consistency, Isolation, Durability.

26
Q

What are the transaction isolation levels and what do they prevent?

A

Isolation levels include READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE,. They are used to determine the degree of isolation between each transactions. There is a trade off between data consistency and system performace/concurrency.

27
Q

What are dirty reads

A

non repeatable reads

A dirty read occurs when a transaction reads data that has been modified by another uncommitted transaction. This can lead to inconsistent or incorrect data being read because the changes might be rolled back in the other transaction.

28
Q

What is normalization?

A

Normalization is the process of organizing a database to reduce redundancy and improve integrity.

29
Q

What are the requirements for different levels of normalization?

A

1NF: Atomic columns. 2NF: No partial dependency. 3NF: No transitive dependency. BCNF: Each determinant is a candidate key.

30
Q

What is a view?

A

A view in SQL is a virtual table that provides a way to simplify complex queries by storing a predefined SELECT statement. Views don’t store actual data; instead, they store a query that generates results when accesse

Consider a Customers table and a Orders table. We can create a view to show customer order details.

CREATE VIEW CustomerOrders AS
SELECT Customers.CustomerID, Customers.Name, Orders.OrderID, Orders.OrderDate
FROM Customers
JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

31
Q

What is a DAO?

A

A DAO (Data Access Object) is a design pattern that provides an abstraction layer between the application and the datasource.

EX: A collection of CRUD methods

32
Q

What is the danger of putting values directly into our queries?

A

Directly inserting values risks SQL injection attacks and reduces maintainability.

33
Q

How do we specify dependencies using sbt?

A

Dependencies are specified in the build.sbt file using libraryDependencies += <dependency>.</dependency>

34
Q

What is a port number?

A

A port number is a communication endpoint used to identify specific processes on a server.

35
Q

What’s the default port for Postgres?

A

The default port for PostgreSQL is 5432.

36
Q

What is an Index?

A

An index is a database object that provides quick lookups of a column improving the speed of data retrieval

37
Q

What advantages does creating an Index give us? Disadvantages?

A

Advantages: Faster data retrieval. Disadvantages: Increased storage and slower writes.

38
Q

What is CRUD?

A

CRUD stands for Create, Read, Update, Delete and they are operations used on databases

39
Q

What does it mean that an operation or transaction on a data store is atomic?

A

An atomic operation is indivisible, ensuring all steps succeed or none at all.

40
Q

What does ACID stand for?

A

ACID stands for Atomicity, Consistency, Isolation, Durability.

41
Q

What does BASE stand for?

A

BASE stands for Basically Available, Soft state, Eventual consistency.

Basically Available : reads and writes are available as much as possible, using multiple machines in a cluster

Soft state : records stored in the database may be inconsistent across a cluster, some may be more up to date than others

Eventual consistency : if the databases runs long enough, it will achieve consistent data across the cluster BASE favors Availability and Partition Tolerance in a distributed database.

42
Q

Atomicity

A

Atomicity : a transaction succeeds or fails and a single unit

43
Q

Consistency

A

Consistency : a transaction takes the database from one valid state to another (NOT the same as CAP Consistency)

44
Q

Isolation

A

Isolation : multiple transactions taking place at the same time don’t interfere with each other

45
Q

Durability

A

Durability : transactions satisfy ACID even in the case of disaster (power shut off to DB) It’s useful to start thinking about ACID as a property of SQL databases, but really SQL and NoSQL databases both implement useful features of the other.

46
Q

What is a materialized view

A

A materialized view is similar to a regular view, but with one significant difference: it stores the result of the query physically. The data in a materialized view is precomputed and saved, so

CREATE MATERIALIZED VIEW view_name AS
SELECT column1, column2
FROM table_name
WHERE condition;