50 Interview Questions Flashcards

1
Q

What is a database?

A

An organized collection of data

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

What is DBMS?

A

Database Management System. The software used to create and manage the database.

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

What is RDBMS?

A

Relational Database Management System. RDMS stores data in tables and the relationships between those tables can be defined by common fields.

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

What is SQL?

A

Structured Query Language. The standard language for RDBMS

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

What is the difference between SQL and mySQL?

A

SQL is the language used to manipulate relational databases. MySQL is a RDBMS

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

What are Tables and Fields?

A

Tables are collections of data stored in rows and columns. Fields are the columns. Rows are the records.

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

What are constraints in SQL?

A

Rules for data in a table. Can be applied during creation of a table or after creation using ALTER TABLE command

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

Constraint 1: NOT NULL

A

Prevents NULL values from being inserted into a column

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

Constraint 2: CHECK

A

Verifies that all values in a field satisfy a condition

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

Constraint 3: DEFAULT

A

Automatically assigns a default value if no value has been specified for the field.

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

Constraint 4: UNIQUE

A

Ensures unique values to be inserted into the field. Unlike primary key, there can be multiple unique constraints defined per table.

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

Constraint 5: INDEX

A

Indexes a field providing faster retrieval of records.

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

Constraint 6: PRIMARY KEY

A

Indexes a field providing faster retrieval of records. Must contain UNIQUE values and has implicit NOT NULL constraint. A table in SQL is strictly restricted to have one and only one primary key, which is comprised of single or multiple fields

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

Constraint 7: FOREIGN KEY

A

Comprises of single or collection of fields in a table that essentially refer to the PRIMARY KEY in another table. Foreign key constraint ensures referential integrity in the relation between two tables.

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

What is a JOIN?

A

The SQL Join clause is used to combine records (rows) from two or more tables in a SQL database based on a related column between the two.

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

INNER JOIN

A

Retrieves records that have matching values in both tables involved in the join.
SELECT *
FROM Table_A
INNER JOIN Table_B;

17
Q

LEFT JOIN

A
Retrieves all the records/rows from the left and the matched records/rows from the right table.
SELECT *
FROM Table_A A
LEFT JOIN Table_B B
ON A.col = B.col;
18
Q

RIGHT JOIN

A
Retrieves all the records/rows from the right and the matched records/rows from the left table.
SELECT *
FROM Table_A A
RIGHT JOIN Table_B B
ON A.col = B.col;
19
Q

FULL (OUTER) JOIN

A
Retrieves all the records where there is a match in either the left or right table.
SELECT *
FROM Table_A A
FULL JOIN Table_B B
ON A.col = B.col;
20
Q

What is a SELF-JOIN?

A

regular join where a table is joined to itself based on some relation between its own column(s).
SELECT A.emp_id AS “Emp_ID”,A.emp_name AS “Employee”,
B.emp_id AS “Sup_ID”,B.emp_name AS “Supervisor”
FROM employee A, employee B
WHERE A.emp_sup = B.emp_id;

21
Q

What is a CROSS-JOIN?

A

a cartesian product of the two tables included in the join.
SELECT stu.name, sub.subject
FROM students AS stu
CROSS JOIN subjects AS sub;

22
Q

What is an INDEX?

A

data structure that provides quick lookup of data in a column or columns of a table.An index helps to speed up SELECT queries and WHERE clauses, but it slows down data input, with the UPDATE and the INSERT statements. Indexes can be created or dropped with no effect on the data.

CREATE INDEX index_name 	 /* Create Index */
ON table_name (column_1, column_2);

DROP INDEX index_name; /* Drop Index */

23
Q

What is data integrity?

A

the assurance of accuracy and consistency of data over its entire life-cycle

24
Q

What is a query?

A

is a request for data or information from a database table or combination of tables. A database query can be either a select query or an action query.

25
Q

What is a subquery?

A

a query within another query

26
Q

What are the two types of subqueries?

A

A correlated subquery cannot be considered as an independent query, but it can refer the column in a table listed in the FROM of the main query.

A non-correlated subquery can be considered as an independent query and the output of subquery is substituted in the main query.

27
Q

UNION

A

SELECT name FROM Students /* Fetch the union of queries */
UNION
SELECT name FROM Contacts;

SELECT name FROM Students /* Fetch the union of queries with duplicates*/
UNION ALL
SELECT name FROM Contacts;

28
Q

MINUS

A

SELECT name FROM Students /* Fetch names from students /
MINUS /
that aren’t present in contacts */
SELECT name FROM Contacts;

29
Q

INTERSECT

A

SELECT name FROM Students /* Fetch names from students /
INTERSECT /
that are present in contacts as well */
SELECT name FROM Contacts;

30
Q

What are the different types of relationships in sequel?

A

One-to-One - This can be defined as the relationship between two tables where each record in one table is associated with the maximum of one record in the other table.

One-to-Many & Many-to-One - This is the most commonly used relationship where a record in a table is associated with multiple records in the other table.

Many-to-Many - This is used in cases when multiple instances on both sides are needed for defining a relationship.

Self Referencing Relationships - This is used when a table needs to define a relationship with itself.

31
Q

What is an alias?

A

It is a temporary name assigned to the table or table column for the purpose of a particular SQL query. An alias is represented explicitly by the AS keyword but in some cases the same can be performed without it as well.

32
Q

What is a view?

A

A view in SQL is a virtual table based on the result-set of an SQL statement. A table contains data, a view is just a SELECT statement which has been saved in the database

33
Q

What is normalization?

A

Normalization represents the way of organizing structured data in the database efficiently.

34
Q

DELETE statement

A

statement is used to delete rows from a table.

DELETE FROM Candidates
WHERE CandidateId > 1000;

35
Q

TRUNCATE statement

A

used to delete all the rows from the table and free the space containing the table.

TRUNCATE TABLE Candidates;`

36
Q

DROP statement

A

used to remove an object from the database. If you drop a table, all the rows in the table is deleted and the table structure is removed from the database.

37
Q

What is the difference between DROP and TRUNCATE statements?

A

If a table is dropped, all things associated with the tables are dropped as well. This includes - the relationships defined on the table with other tables, the integrity checks and constraints, access privileges and other grants that the table has. To create and use the table again in its original form, all these relations, checks, constraints, privileges and relationships need to be redefined. However, if a table is truncated, none of the above problems exist and the table retains its original structure.