SQL Flashcards

(35 cards)

1
Q

What is SQL?

A

A language to manage and query data in relational databases.

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

What is a table in SQL?

A

A set of rows and columns that stores related data.

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

What is a primary key?

A

A column that uniquely identifies each row in a table.

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

What is a foreign key?

A

A column that links to the primary key of another table.

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

How do you get data from a table?

A

Use SELECT.

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

How do you insert data into a table?

A

Use INSERT INTO.

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

How do you update data in a table?

A

Use UPDATE with SET and WHERE.

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

How do you delete data from a table?

A

Use DELETE FROM with WHERE.

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

How do you filter rows?

A

Use WHERE clause.

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

How do you sort results?

A

Use ORDER BY.

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

How do you limit the number of rows?

A

Use LIMIT.

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

What is an INNER JOIN?

A

Returns matching rows from both tables.

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

What is a LEFT JOIN?

A

Returns all rows from the left table, even if there’s no match in the right.

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

What is a RIGHT JOIN?

A

Returns all rows from the right table, even if there’s no match in the left.

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

What is a FULL OUTER JOIN?

A

Returns all rows from both tables, with NULLs where there’s no match.

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

How do you count rows?

17
Q

How do you find the average value?

18
Q

How do you find the total sum?

19
Q

How do you group data?

A

Use GROUP BY.

20
Q

How do you filter grouped results?

21
Q

What is an index in SQL?

A

A structure that speeds up searches on a column.

22
Q

When should you create an index?

A

When a column is used often in WHERE, JOIN, or ORDER BY.

23
Q

How do you check query performance?

A

Use EXPLAIN before the query.

24
Q

How do you optimize a slow query?

A

Use EXPLAIN, add indexes, avoid SELECT *, and rewrite joins.

25
What is a transaction?
A group of SQL operations that succeed or fail together.
26
What does ACID stand for?
Atomicity, Consistency, Isolation, Durability.
27
How do you start a transaction?
Use BEGIN or START TRANSACTION.
28
How do you end a successful transaction?
Use COMMIT.
29
How do you cancel a transaction?
Use ROLLBACK.
30
What is a view?
A saved SQL query that you can query like a table.
31
What is a subquery?
A query inside another query.
32
What is a CTE?
A Common Table Expression that makes queries easier to read.
33
How do you prevent SQL injection?
Use parameterized queries or prepared statements.
34
Why avoid SELECT *?
It selects unnecessary data and can slow performance.
35
Why use aliases in SQL?
To make column or table names shorter or clearer.