SQL Flashcards

(45 cards)

1
Q

What does SQL stand for?

A

Structured Query Language

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

True or False: PostgreSQL is an open-source relational database management system.

A

True

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

Fill in the blank: In SQL, the command to retrieve data from a database is ______.

A

SELECT

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

What is the purpose of normalization in databases?

A

To reduce data redundancy and improve data integrity.

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

What does the acronym ACID stand for in database transactions?

A

Atomicity, Consistency, Isolation, Durability

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

Which SQL command is used to add new records to a table?

A

INSERT

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

True or False: A primary key can contain duplicate values.

A

False

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

What type of relationship is represented by a foreign key in a database?

A

A relationship between two tables.

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

Multiple choice: Which of the following is NOT a type of JOIN in SQL? A) INNER JOIN B) OUTER JOIN C) CROSS JOIN D) LINK JOIN

A

D) LINK JOIN

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

What is a database schema?

A

The structure that defines the organization of data in a database.

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

Fill in the blank: The command to delete records from a table in SQL is ______.

A

DELETE

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

True or False: A unique constraint allows for duplicate values in a column.

A

False

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

What is the purpose of the GROUP BY clause in SQL?

A

To arrange identical data into groups.

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

Which SQL command is used to modify existing records in a table?

A

UPDATE

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

What is the result of a LEFT JOIN?

A

It returns all records from the left table and matched records from the right table.

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

What is the difference between a primary key and a foreign key?

A

A primary key uniquely identifies a record in its own table, while a foreign key links to a primary key in another table.

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

Multiple choice: Which SQL function is used to count the number of rows in a result set? A) COUNT() B) SUM() C) AVG() D) TOTAL()

A

A) COUNT()

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

Fill in the blank: The SQL command ______ is used to create a new table.

A

CREATE TABLE

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

True or False: In PostgreSQL, data types can be customized by the user.

20
Q

What is a composite key?

A

A key that consists of two or more attributes that together uniquely identify a record.

21
Q

What does the term ‘denormalization’ refer to?

A

The process of combining tables to reduce the complexity of queries and improve performance.

22
Q

Multiple choice: Which of the following is a valid SQL data type? A) INTEGER B) NUMBER C) TEXT D) All of the above

A

D) All of the above

23
Q

What is the SQL command to create an index?

24
Q

Fill in the blank: The ______ clause is used to filter records in a SQL query.

25
True or False: The SQL command ALTER TABLE can be used to add a new column to an existing table.
True
26
What is the purpose of the HAVING clause?
To filter records after aggregation.
27
What is an ERD? Why would you use one?
Entity Relationship Diagram * To understand the structure and relationships between entities in a database system.
28
What is a database used for?
A centralised and structured way to store data so it can be organised, accessed and managed easily.
29
What is an entity in the context of databases?
A real-world object or concept about which information is stored e.g. person, event.
30
What is an attribute in the context of databases?
A quality, property or characteristic that defines an entity or entity type (columns in database tables).
31
What is a relational database?
A method of storing related data in table(s) made up of columns and rows. Tables can be connected using primary or foreign keys.
32
True or False: there is a `DATETIME` data type in PostgreSQL.
False - the `TIMESTAMP` data type is used to store combined date and time values in PostgreSQL.
33
What is a primary key in a relational database?
A column or a set of columns in a table whose values uniquely identify a row in a database table.
34
What is a `JOIN`?
An action that combines rows from two or more database tables based on a related column.
35
How does a `LEFT JOIN` differ from an `INNER JOIN`?
`INNER JOIN` only displays records with matching values in both database tables; `LEFT JOIN` displays all records from left table, with matching values from right table and `NULL` values for non-matching records.
36
What is a view in SQL?
A virtual table with contents defined by a query which is stored and can be referenced in later queries.
37
* No duplicate rows * Each cell only contains a single value * Values should be non-divisible (context dependent) These are features of `____` Normal Form?
1st (Normal Form)
38
* No partial dependencies - every non-key attribute is fully dependent on the primary key. Feature of `___` Normal Form?
Second (Normal Form)
39
3rd Normal Form has the feature of 'no transitive dependencies' - what does this mean?
All fields must only be determinable by the primary key, not by non-key attributes. ## Footnote Example - Consider a table for employees with columns: EmployeeID (primary key), Department, Manager. If Department is dependent on EmployeeID, and Manager is dependent on Department, then there's a transitive dependency. To eliminate this, you'd create a new table for Departments with columns: DepartmentID (primary key), Department, Manager.
40
What is a CTE? | In database context.
Common Table Expression - The result set of a query which exists temporarily for use in the context of a larger subsequent query.
41
What is a window function?
A function type in SQL that allows calculations across multiple rows that are related to the current row.
42
What are the relationship types in ERDs?
* one-to-one * one-to-many/many-to-one * many-to-many
43
Which notation is typically used to denote relationship type in ERDs?
Crow's foot notation
44
How do you auto-increment the primary key with the addition of a new entry in a database table? | PostgreSQL
`GENERATED ALWAYS AS IDENTITY` when creating the primary key column in a `CREATE TABLE` statement.
45