SQL Flashcards

1
Q

What are DML and DDL ?

A

Data definition language - insert, update, delete
Data manipulation language - i.e. DB schemas | how the data should redide in database | CREATE, ALTER, DROP, TRUNCATE

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

Aggrefate functions with examples

A

count, sum, min, max, avg

SELECT CITY, COUNT(CITY) FROM Customers
GROUP BY CITY

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

Primary key vs Unique key

A

Primary key - unique identifier for each row
non null
only one
clustered index

Unique - when uniquness is required
could be null
could be several
non-clustered index

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

What are transactions

A

Series of data manupulation statements that must fully complete or fully fail

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

What is ACID

A

atomic - if change is commited - then only whole change. You can never see half of change
consistent - the change can only happen if the new state of the system will be valid (none of the constraints you have on related data will ever be violated)
isolated - no one else sees any part of change until it is commited. If two transactions are executing concurrently, each one will see the world as if they were executing sequentially
durable - committed data stored forever | when transaction ended - it has been recorded (is not in RAM)

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

What transaction isolation levels do you know?

A

The degree of which one transaction is visible to another transaction
MySQL:
READ UNCOMMITTED - dirty read. could read uncomitted data
READ COMMITTED - each consistent read in same transaction sets its own snapshot
REPEATABLE READ - default. Consistent multiple reads within same transaction will get snapshot established by the first read
SERIALIZABLE.

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

Are db indexes useful? What is the role of them?

A

Speed up search queries

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

What kinds of joins do you know?

A

Inner
Left
Right
Full

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

What is the difference between innner join and outer join?

A

inner - only shows rows if they are in both tables
outer - shows rows from left/right table with empty or existing data from other table

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

Why many indexes are not good for performance?

A

makes more update/insert operations
uses more space on disk

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

Views. Why they are needed

A

avoid extra tables
allow access to views, not to tables
do not take additional store in db

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

Which of SELECT, UPDATE, DELETE, INSERT
performance is mostly affected by index performance

A

the more indexes - the slower INSERT, UPDATE, DELETE

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

What does it mean database de-normalization?

A

grouping data or adding redundant copies of data
=> improve read performance
=> decrease write performance & use more space

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

What are the ways to increase performance of database?

A

Sharding
CQRS
Replication
Indexes
De-normalization
?Isolation levels

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

What os the difference between SQL and NoSQL

A

table based RDBMS vs document based, key-value pairs, graph databases or wide-column stores

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