SQL Flashcards

1
Q

[1] What is oracle epoch function?
[2] What given code do: extract(epoch from bilet.data_zakupu) - extract(epoch from bilet.bilet_start) do?

A

[1] epoch is a function that returns the number of seconds that have elapsed since 1 January 1970 (in another OS date can be different)

[2] it determines the difference between when ticket was activated and when it was bought

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

What is the difference between UNION and UNION ALL?

A

UNION - removes duplicated records (where all columns in the results are the same)

UNION ALL - does not remove additional columns

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

What is the difference between UNION and UNION ALL?

A

UNION - removes duplicated records (where all columns in the results are the same)

UNION ALL - does not remove additional columns

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

What are join clauses?

A

The join clause combines columns with related values from two or more tables to create a new table. There are four main types of SQL join clause:

a) JOIN returns records with matching values in both tables
b) LEFT JOIN returns all records from the left table and matching records from the right table
c) RIGHT JOIN returns all records from the right table and matching records from the left table
d) FULL JOIN returns all records from both tables

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

How to create empty tables with the same structure as another table?

A

create table xyz_new as select * from xyz where 1=0;

LIMITATIONS:
The following things will not be copied to the new table:
sequences
triggers
indexes
some constraints may not be copied
materialized view logs

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

What is the difference between the RANK() and DENSE_RANK() functions?

A

RANK
The RANK() function in the result set defines the rank of each row within your ordered partition. If both rows have the same rank, the next number in the ranking will be the previous rank plus a number of duplicates. If we have three records at rank 4, for example, the next level indicated is 7.

The DENSE_RANK() function assigns a distinct rank to each row within a partition based on the provided column value, with no gaps. It always indicates a ranking in order of precedence. This function will assign the same rank to the two rows if they have the same rank, with the next rank being the next consecutive number. If we have three records at rank 4, for example, the next level indicated is 5.

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

What is a Primary key?

A

Table - SQL Interview Questions - EdurekaA Primary key in SQL is a column (or collection of columns) or a set of columns that uniquely identifies each row in the table.
Uniquely identifies a single row in the table
Null values not allowed

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

What are Constraints?

A

Constraints in SQL are used to specify the limit on the data type of the table. It can be specified while creating or altering the table statement. The sample of constraints are:

NOT NULL
CHECK
DEFAULT
UNIQUE
PRIMARY KEY
FOREIGN KEY

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

What is the difference between DELETE and TRUNCATE statements?

A

TRUNCATE:
- remove all records
- it put locks on the whole table
- faster than delete as it doesn’t scan records
- DDL query
- do not need to commit, you cannot rollback data

DELETE:
- can remove 0 to all records
- slower than TRUNCATE
- DML query
- need commit, can be rolledback

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

What do you mean by Denormalization?

A

A design techniques that helps to increase the performance of the entire infrastructure as it introduces redundancy into a table

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

What is Normalization and what are the advantages of it?

A

Normalization in SQL is the process of organizing data to avoid duplication and redundancy. Some of the advantages are:

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

What is the ACID property in a database?

A

1) Atomicity: Atomicity refers to the transactions that are completely done or failed where transaction refers to a single logical operation of a data. It means if one part of any transaction fails, the entire transaction fails and the database state is left unchanged.

2) Consistency: Consistency ensures that the data must meet all the validation rules. In simple words, you can say that your transaction never leaves the database without completing its state.

3) Isolation: The main goal of isolation is concurrency control.

4) Durability: Durability means that if a transaction has been committed, it will occur whatever may come in between such as power loss, crash or any sort of error.

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