Databases and SQL Flashcards

1
Q

What is normalization?

A

The process of organizing data to reduce redundancy and improve data integrity.

Normalization breaks large tables into smaller ones and establishes relationships using foreign keys.

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

What is denormalization?

A

The process of combining tables to improve read performance by introducing redundancy.

Denormalization is often used in data warehousing where read speed is more critical than write efficiency.

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

What does the ‘A’ in ACID properties stand for?

A

Atomicity.

Atomicity means a transaction is either completed or not done at all.

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

What does the ‘C’ in ACID properties stand for?

A

Consistency.

Consistency means the database must be valid before and after a transaction.

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

What does the ‘I’ in ACID properties stand for?

A

Isolation.

Isolation ensures transactions happen independently without interference.

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

What does the ‘D’ in ACID properties stand for?

A

Durability.

Durability means once committed, a transaction remains even in case of a failure.

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

What is a transaction?

A

A unit of work performed against a database.

Rollback ensures actions don’t partially execute in an operation failure scenario.

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

What is an index?

A

A data structure that improves the speed of data retrieval.

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

What is a primary index?

A

Based on the primary key (unique identifier).

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

What is a secondary index?

A

Non-primary key columns.

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

What is a composite index?

A

Index on multiple columns.

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 records 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 records from the left table, with matching row from 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 records from the right table, with matching rows on the left.

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

What does FULL OUTER JOIN do?

A

Returns record when there is a match in either table.

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

What is the first normalization form (1NF)?

A

Eliminate repeating groups and contain a primary key.

Mixing data types within the same column is not permitted (atomic columns).

17
Q

What is the second normalization form (2NF)?

A

Remove partial dependency.

Every non-key column must depend on the whole primary key.

18
Q

What is the third normalization form (3NF)?

A

Remove transitive dependencies.

Every non-key attribute should depend on the key, the whole key and nothing but the key.

19
Q

What is the fourth normalization form (4NF)?

A

Multivalued dependencies in a table must be multivalued dependencies on the key.

20
Q

What is the fifth normalization form (5NF)?

A

The table cannot be described as the logical result of joining some other tables together.

21
Q

What are foreign keys and how do they ensure referential integrity?

A

A foreign key is a column or combination of columns in a table whose value matches in another column. It ensures referential integrity by enforcing the rule the every foreign key value refers to a valid primary key.

22
Q

Explain the difference between clustered and non-clustered indexes:

A

Clustered index determines/stores the physical order of data in a table. Non-Clustered index does not affect the physical order but instead contains a copy of the index columns and a pointer to the actual data.

23
Q

What is a deadlock in databases, and how can you prevent it?

A

When two or more transactions are stuck waiting for each to release locks on resources they need, creating a standstill situation.

24
Q

How would you optimize a slow-performing SQL query

A
  • Use indexes effectively
  • Reduce the scope of query
  • Optimize JOIN operations
  • Normalize database tables
  • Utilize stored procedures
25
Q

What are stored procedures and when would you use them?

A

A prepared SQL code that you can save and reuse. When you want to reduce time to query the same information, as the stored procedure is already compile.

26
Q

How do database transactions work in distributed systems?

A

In a distributed system, data is spread across multiple databases or servers. Database transactions have to follow the principles of ACID, to ensure data consistency and atomicity.

27
Q

Explain sharding vs partitioning in databases

A

Sharding disperses data across various databases or servers, while partitioning segregates data within a single database instance into subsets.