Unit 3 - SQL Queries Flashcards

1
Q

ALTER TABLE

A

A statement that makes structural changes to a table.

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

AVG

A

The function that calculates the average of non-null values.

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

AVG Function

A

A function that calculates the average value of the entries in a numeric column. It is commonly used in statistical calculations and data analysis.

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

Aggregate

A

To combine individual items or objects and treat the combined set as a single unit.

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

Aggregate Function

A

A function that operates on multiple records and returns a single value that summarizes them, such as producing a count, sum, or average.

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

Boolean Expression

A

An expression that can be evaluated as either true or false.

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

CHECK

A

A constraint that uses a Boolean expression to evaluate whether the value is valid when inserted into or updated in the column.

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

COALESCE

A

This function in PostgreSQL returns the first non-null value from a list of expressions. It evaluates multiple arguments in order, returning the first non-null value encountered.

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

COUNT

A

The function that returns the number of rows in a result set.

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

Cascading Order

A

A multilevel sequence used for complex sorting operations.

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

Casting

A

To change the data type for all entries in a column when that column’s data type changes.

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

Clause

A

An individual command used in a statement.

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

Constraint

A

A rule that imposes limitations on what can be done. In the context of a database table, a constraint limits what data can be entered.

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

DISTINCT

A

A keyword in PostgreSQL that enables you to limit query results to unique values from a specified column in a result set. It can be used on its own or with an aggregate function such as SUM.

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

DROP TABLE

A

A SQL statement that removes a table from a database.

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

FROM Clause

A

The part of a SQL SELECT statement that identifies which tables should be used as the data source.

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

Foreign Key

A

The term foreign key refers to when a primary key from one table appears in another.

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

GROUP BY

A

A clause that calculates aggregates within a group of rows, with groups created based on values in one or more specified columns.

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

HAVING Clause

A

A clause that enables you to filter the results of a GROUP BY clause according to specified conditions.

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

INSERT INTO

A

A statement that creates a new row or updates an existing row in a table.

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

LIMIT Clause

A

A clause that limits the number of rows returned by a query.

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

MAX

A

The function that returns the largest of the non-null values.

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

MAX Function

A

A function that reports the largest value for a certain column in a dataset or result set.

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

MIN

A

The function that returns the smallest of the non-null values.

25
Q

MIN Function

A

A function that reports the smallest value for a certain column in a dataset or result set.

26
Q

OFFSET Clause

A

This clause specifies a maximum number of rows to return from a query to restrict the number of rows returned. like when you skip pages on a search, it skips the previous data to show the next page (pagination)

27
Q

Pseudo-Type

A

A data type that is used on data that is not directly stored in a table, such as data in a result set.

28
Q

RANK

A

This function returns the rank of the row based on the value. A row with the same value as the prior row will return the same rank.

29
Q

RELEASE

A

A statement that enables you to release a savepoint that is no longer needed.

30
Q

RETURNING Clause

A

A clause that can be added to an UPDATE/ INSERT statement to return the updated rows so the results can be inspected.
use RETURNING * at the end (or column names

31
Q

ROLLBACK

A

A statement that enables you to undo a transaction.

32
Q

ROUND Function

A

A function that rounds numeric values to a specified number of decimal places or to the nearest whole number.

33
Q

Referential Integrity

A

A set of constraints that ensure data and relationship integrity by enforcing rules about primary key constraints, foreign keys, and cascading operations.

34
Q

Result Set

A

The results returned from a SELECT statement.

35
Q

Return True

A

To match the criteria required by a WHERE clause.

36
Q

SAVEPOINT

A

A statement that creates a saved point in a transaction that you can roll back to with the ROLLBACK TO statement.

37
Q

SELECT Clause

A

The part of a SELECT statement that specifies which columns should be included.

38
Q

SELECT Statement

A

A SQL statement that retrieves rows of data from one or more tables.

39
Q

STDDEV

A

This function returns the standard deviation based on the non-null values.

40
Q

SUM

A

The SUM function returns the sum of all non-null values.

41
Q

Schema Browser

A

A list of table names, column names, and data types contained within a database.

42
Q

Serial

A

In Postgres, the unique identifier assigned to each record as it is entered into a table. (Can use IDENTITY instead as a SQL standard)

43
Q

Statement

A

A standalone instruction that the DBMS can interpret and execute.

44
Q

TRUNC() Function

A

A function in PostgreSQL that truncates a numeric value to a specified number of decimal places or removes the decimal part altogether.

TRUNC(numeric_expression, decimal places)

45
Q

Transaction

A

A set of steps that add, modify, or delete data in a database.

46
Q

UNIQUE

A

UNIQUE constraints ensure that all values in a column are different.

47
Q

UPDATE

A

A statement that updates the content of one or more columns for one or more rows.

48
Q

VARIANCE

A

This function returns the variance of non-null values.

49
Q

WHERE Clause

A

A SQL clause that applies conditions to filter the result set.

50
Q

CREATE INDEX

A

Indexes the specified column so that searches based on it run quickly.

51
Q

CHECK

A

Ensures that the values in a column satisfy a specific condition

52
Q

PRIMARY KEY

A

Designates the primary key field in the table, which applies the *UNIQUE and NOT NULL constraints and indexes the field.

53
Q

CREATE TABLE pet (
pet_id int PRIMARY KEY,
pet_name VARCHAR(40) NOT NULL,
species VARCHAR(40) NOT NULL,
breed VARCHAR(40) NULL,
Birthdate DATE,
owner_id int,
CONSTRAINT fk_owner
FOREIGN KEY (owner_id)
REFERENCES owner(owner_id)
);

A

CONSTRAINT fk_owner defines which table is being connected to; fk stands for foreign key

FOREIGN KEY (owner_id) defines which field in the pet table should be on the “many” side of the relationship. You know it’s the main side because it’s the foreign key;
recall that the primary key side is the “one” side.

REFERENCES owner(owner_id) defines which field in the owner table should be on the “one” side of the relationship.

54
Q

PostgreSQL - difference between Sequence and Serial

A

Serial auto increments by 1, whereas sequence lets you customize incrementation, start value, and min/max values

55
Q

Generic way of listing all foreign keys in a database for every table

A

SELECT conrelid::regclass AS table_name,
conname AS foreign_key,
pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = ‘f’
AND connamespace = ‘public’::regnamespace
ORDER BY conrelid::regclass::text, contype DESC;

56
Q

Delete table without needing to check for related tables

A

CASCADE and IF EXISTS

57
Q

What does this do?
COALESCE(SUM(total), 0)

A

Ensures that if the result of SUM(total) is NULL (which happens if there are no rows matching the condition), it defaults to 0.

58
Q

IDENTITY

A

SQL Standard to define an auto-incrementing column.

EX: grade_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY

GENERATED ALWAYS always assigns an incrementing value for each record

GENERATED BY DEFAULT assigns an incrementing value only if a specific value is not entered for it

59
Q
A