SQL Concepts Flashcards

1
Q

What is a database?

A

A db is an organized collection of data, stored and retrieved digitally from a variety of sources

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

What is DBMS?

A

A DBMS is a database management system. It’s responsible for the creation, deletion, updates and otherwise interaction with a database.

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

RDBMS vs. DBMS

A

A relational database management system exists surrounding the concept of a table. A way to reference each individual table is where “relational” comes from.

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

What is SQL?

A

Structured Query Language.

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

What are tables and fields?

A

A table is an organized collection of data stored in the form of rows and columns. Columns can be categorized as vertical and rows as horizontal. The columns in a table are called fields while the rows can be referred to as records.

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

What are Constraints in SQL?

A

Constraints are used to specify the rules concerning the data in a table. They are:
NOT NULL - Restricts NULL value from being inserted into a column.
CHECK - Verifies that all values in a field satisfy a condition.
DEFAULT - Automatically assigns a default value if no value has been specified for the field.
UNIQUE - Ensures unique values to be inserted into the field.
INDEX - Indexes a field providing faster retrieval of records.
PRIMARY KEY - Uniquely identifies each record in a table.
FOREIGN KEY - Ensures referential integrity for a record in another table.

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

What is a Primary Key?

A

The PRIMARY KEY constraint uniquely identifies each row in a table. It must contain UNIQUE values and has an implicit NOT NULL constraint.

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

What is a UNIQUE constraint?

A

A UNIQUE constraint ensures that all values in a column are different.

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

What is a FOREIGN KEY?

A

A FOREIGN KEY comprises of single or collection of fields in a table that essentially refers 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
10
Q

What is a JOIN?

A

It’s a way to combine rows from two or more different tables. There is
LEFT JOIN - all the left, whatever matches on the right
INNER JOIN - Only what matches from all
RIGHT JOIN - all the right, whatever matches the left
FULL OUTER JOIN - Wherever there is a match in the left or right

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

What is an Index? Explain the different types

A

A database index is a data structure that provides a quick lookup of data in a column or columns of a table. It enhances the speed of operations accessing data from a database table at the cost of additional writes and memory to maintain the index data structure.

Unique vs. Non-Unique: Unique indexes are indexes that help maintain data integrity by ensuring that no two rows of data in a table have identical key values.

Clustered vs. Non-Clustered: Clustered indexes are indexes whose order of the rows in the database corresponds to the order of the rows in the index. This is why only one clustered index can exist in a given table, whereas, multiple non-clustered indexes can exist in the table.

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

What is Data Integrity?

A

Data Integrity is the assurance of accuracy and consistency of data over its entire life-cycle and is a critical aspect of the design, implementation, and usage of any system which stores, processes, or retrieves data. It also defines integrity constraints to enforce business rules on the data when it is entered into an application or a database.

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

What is a Query?

A

A query is a request for data or information from a database.

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

What is a subquery?

A

A subquery is a query within another query, also known as a nested query or inner query. There are two types:

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

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

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

What is SELECT?

A

SELECT operator in SQL is used to select data from a database. The data returned is stored in a result table, called the result-set.

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

What are some common clauses used with SELECT query in SQL?

A

The two I’m most familiar with are WHERE (some logic), ORDER BY, GROUP BY, and HAVING

17
Q

What are UNION, MINUS and INTERSECT commands?

A

They all deal in tandem with the SELECT operator.

UNION: combines and returns the result-set retrieved by two or more SELECT statements.

MINUS: remove duplicates from the result-set obtained by the second SELECT query from the result-set obtained by the first SELECT query and then return the filtered results from the first.

INTERSECT: returns the result-set where both

18
Q

What is a Cursor? How do you use it?

A

A database cursor is a control structure that allows for the traversal of records in a database. Cursors, in addition, facilitates processing after traversal, such as retrieval, addition, and deletion of database records. They can be viewed as a pointer to one row in a set of rows.

19
Q

What are Entities and Relationships?

A

Entity: An entity can be a real-world object, either tangible or intangible, that can be easily identifiable. For example, in a college database, students, professors, workers, departments, and projects can be referred to as entities. Each entity has some associated properties that provide it an identity.

Relationships: Relations or links between entities that have something to do with each other. For example - The employee’s table in a company’s database can be associated with the salary table in the same database.

20
Q

List different types of relationships in SQL

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: 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.

21
Q

What is an Alias in SQL

A

An alias is a feature of SQL that is supported by most, if not all, RDBMSs. It is a temporary name assigned to the table or table column for the purpose of a particular SQL query.

22
Q

What is a View?

A

A view in SQL is a virtual table based on the result-set of an SQL statement.

23
Q

Normalization vs. Denormalization

A

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

24
Q

Various forms of Normalization

A

First Form Normalization: every attribute is single-valued (think a table filled with students and books: first form is when there are many inputs for each student with one book listed for each input)

Second Form Normalization: A relation is in second normal form if it satisfies the conditions for the first normal form and does not contain any partial dependency.

Third Form Normalization: Basically every non-prime item has a separate table

25
Q

TRUNCATE, DELETE, DROP

A

DELETE for rows in a table

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

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

26
Q

What are Aggregate and Scalar Functions?

A

An aggregate function performs operations on a collection of values to return a single scalar value.

Aggregates:
AVG
COUNT
MIN
MAX
SUM
FIRST
LAST

SCALARS:
LEN
UCASE
LCASE
MID
CONCAT
RAND
ROUND
NOW
FORMAT

27
Q

What is OLTP?

A

OLTP is OnLine Transaction Processing.

28
Q

What is Pattern Matching is SQL?

A