SQL Flashcards
Explain what SQL is. What are some SQL databases?
SQL stands for Structured Query Language and it allows the user to access and manipulate databases.
Some SQL Databases: MySQL MariaDB Oracle PostgreSQL MSSQL
What are the 5 sublanguages of SQL? Which commands correspond to each of them?
DDL - Data Definition Language: CREATE, ALTER, DROP
DML - Data Manipulation Language: INSERT, UPDATE, DELETE
DQL - Data Query Language: SELECT
DCL - Data Control Language: GRANT, REVOKE
TCL - Transaction Control Language: COMMIT, ROLLBACK, SAVEPOINT
What is the difference between DELETE, DROP, and TRUNCATE commands?
DELETE (DML) - Used to delete one or more rows of a table
DROP (DDL) - Used to drop a whole table
TRUNCATE (DDL) - Used to delete all rows in a table in one go. Cannot be used with a where clause
What are some SQL clauses you can use with SELECT statements?
WHERE - Specifies criteria to retrieve from the results of the SELECT statement
HAVING - Filters the results of GROUP BY, HAVING uses the same restrictions as the WHERE clause
GROUP BY - Groups the selected rows based on identical values in a column or expression
ORDER BY - Allows you to specify the columns by which the results table is to be sorted
What is the difference between WHERE and HAVING?
WHERE - Filters the results of a SELECT statement before GROUP BY can be performed
HAVING - Filters the results of a SELECT statement after GROUP BY is performed
Explain what the ORDER BY and GROUP BY clauses do
GROUP BY - Groups selected rows that share identical values and can act as a summary of values if using aggregate functions
ORDER BY - Used to sort values by columns or expressions, does not group values
Explain the concept of relational integrity
Used to ensure accuracy and consistency of data in the relational database. It has three key concepts:
Relational Database - A type of database that stores information in the form of a 2-D table.
Information integrity - The trustworthiness and dependability of information.
Integrity constraints - Sets of rules that can help maintain the quality of information that is acquired
List the integrity constraints
Entity Integrity Constraints - Constraint which ensure that every entity is unique - Primary Key Constraint, Unique Constraint, Auto_Increment Constraint
Domain Constraints - Constraints which ensure a type of data in a column - Type Constraint, Not null constraint, DEFAULT value Constraint, ENUM constraint
Referential Integrity Constraint - Foreign Key Constraint
User Defined Constraint - CHECK Constraint
Define the word “schema”
Schema is the structure of a database
What is a candidate key? What about a surrogate key?
Candidate key is a single or group key that uniquely identifies rows in a table.
Surrogate key- A surrogate key is a system generated (could be GUID, sequence, unique identifier, etc.) value with no business meaning that is used to uniquely identify a record in a table. The key itself could be made up of one or multiple columns (i.e. Composite Key).
What conditions lead to orphan records?
Its a record whose foreign key value references a non-existent primary key value
What are some SQL data types?
CHAR VARCHAR DATE TIME DateTime INT
What is normalization? What are the levels?
Normalization is the process to eliminate data redundancy and enhance data integrity in the table. Normalization also helps to organize the data in the database.
1NF: There are only single valued attributes, there is a unique name for each column, order does not matter
2NF: All columns depend on primary key column, partial dependencies placed in separate table
3NF: Non Primary Key columns should not depend on non pk columns
What are the properties a transaction must follow?
Transaction must follow the ACID properties.
A- Atomicity - By this, we mean that either the entire transaction takes place at once or doesn’t happen at all. There is no midway i.e. transactions do not occur partially. Each transaction is considered as one unit and either runs to completion or is not executed at all.
C-Consistency - This means that integrity constraints must be maintained so that the database is consistent before and after the transaction. It refers to the correctness of a database.
I-Isolation - makes sure that multiple transactions do not interfere with one another.
D- Durability - Make sure that changes in data made by transactions are saved even if a system failure occurs
What is the difference between joins and set operators?
Set Operators - the columns in the tables must be the same.
Joins - if one column is same its enough to join two or more tables.