One Pager Cheat Sheet
- Review the
best SQL Interview Practice Questions
sourced from interviews with top tech companies like Google, Oracle, Amazon, and Microsoft to help you ace the interview. - SQL is a standard language for accessing and manipulating structured databases, such as MySQL, where queries can be used to perform select or action operations and sub-queries can be used to retrieve specific data.
- A nested query or
sub-query
is used to return data from a database, which is then used by the main query as a condition. - A Database Management System (DBMS) is a software used to define, create, and maintain a database, while a Relational Database Management System (RDBMS) is an advanced version of a DBMS which stores data in the form of tables and maintains data integrity by enforcing a set of rules and standards.
- All values in a field must be
unique
and enforced through aunique index
to ensure data stored is consistent and accurate. - A
Primary Key
is a constraint that uniquely identifies each row in a table and can be comprised of single or multiple fields, while aForeign Key
refers to aPrimary Key
in another table to ensure referential integrity. - A
Primary Key
must contain unique values and not allownull
values. - A
JOIN
clause is used to combine rows from two or more tables, with the typesINNER JOIN
,LEFT JOIN
,RIGHT JOIN
andFULL JOIN
, while aSELF JOIN
links a table to itself and aCROSS JOIN
is a Cartesian product of the two tables included in the join. - An
INNER JOIN
only returns records that have a match in both tables, whereas other types of joins return all records from one of the tables regardless of whether there is a match in the other. - You can use
SELECT
,WHERE
,ORDER BY
,GROUP BY
,HAVING
,UNION
,MINUS
,INTERSECT
,TRUNCATE
,DELETE
,DROP
,CREATE VIEW
,ALTER TABLE
andLIKE
commands to query, change and manipulate data in SQL. - The
SELECT DISTINCT
command eliminates duplicate rows from a result set, providing only a distinct set of data different from the plainSELECT
command. - SQL has three major types of relationships: one-to-one, many-to-one, and many-to-many, which all involve linking or associating records of one table to another.
- A one-to-one relationship exists between a person and their passport, as each passport can only belong to one person and vice versa.
- Normalization is a way of structuring data efficiently, while Denormalization is the opposite process that adds redundancy to improve performance, both of which are illustrated via 1NF, 2NF, 3NF, and 4NF.
- Denormalization increases data redundancy to improve query performance, reducing the overhead of
joins
andrelationships
between tables. - Indexing is used to improve the speed of data retrieval from a database table, at the cost of additional time for updates, with
clustered
andnon-clustered
indexing offering different advantages. - No table can have more than one
Clustered Index
, as it would require the data to bephysically stored in multiple orders
, which is not possible. - OLTP
processes
data fromtransactions
inreal time
for day-to-day operations, whereas OLAPanalyzes
aggregated data from OLTP databases and other sources for business decision-making. - OLAP is used to analyze and aggregate data from a data warehouse or other sources for business intelligence and analytics, while OLTP focuses on transaction-oriented applications such as processing orders.
- PostgreSQL is an
enterprise-level DBMS
that supports a variety ofdata types
such asUUID
,Numeric types
,Temporal types
, andJSON
, and also provides features such asTable Partitioning
andString Constants
to help developers build enterprise-level applications. - PostgreSQL is a continuation of the
POSTGRES
project, based on INGRES and developed at the University of California at Berkeley to support relational databases on UNIX-like systems.