SQL Flashcards
What is SQL?
SQL stands for structured query language and it lets you access and manage databases.
What us a unique constraint?
The UNIQUE constraint ensures that all values in a column are different.
What is a view? Materialized view?
A view is a virtual table based on the result set from a SQL statement. Views are not stored in the database and are generated every time. Materialized views are views that are actually stored in the database system.
What are primary keys and foreign keys?
Primary keys are keys in which uniquely identifies a record in a table. Primary keys must contain unique values and cannot be NULL. A table can only have one primary key.
Foreign keys are just keys used to establish relations between tables. They refer to primary key that exists in another table.
What is the order of operations is a SQL statement?
The order is FROM, WHERE, GROUP BY, HAVING, ORDER BY, and SELECT
How can I create an Alias?
The AS keyword just gives a column or table an alias that exits for the duration of the query.
What is a RDBMS?
.An RDBMS is a type of database management system (DBMS) that stores data in a row-based table structure which connects related data elements.
What is a database?
A database is a set of data stored in a computer. This data is usually structured in a way that makes the data easily accessible.
What are the sublanguages of SQL?
DQL, DDL, DCL, DML, TCL, SCL DQL - data query language DDL - data definition language DCL - data control language DML - data manipulation language TCL - transaction control language SCL - Session control
What is cardinality?
It is the uniqueness of values in a column. High cardinality refers to a column being unique meaning no duplicate values, low cardinality means there are some duplicates.
What is a candidate key?
Candidate key is also a unique key to identify a record uniquely in a table but a table can have multiple candidate keys
What are some different constraints on columns?
Not null, unique, primary key, foreign key, default, check and create index.
What is an entity relation diagram?
It is a model or graphical representation that shows relationships between different entities in a system.
WHERE HAVING
So the where clause is used to filter records before grouping is made while the Having clause filters values from a group.
ORDER BY GROUP BY
Order by sorts the result in either ascending or descending order while group by is used to group rows that have the same values.
LIKE
A logical operator that checks whether a string matches a patter.
SUB QUERY
A subquery is a SQL query nested inside a larger query. To use a subquery you can nest it inside another select or update statement but usually they are nested after a WHERE clause.
How does BETWEEN work?
Between just selects values within a range. This could be numbers, text or dates, and it is inclusive.
What is the order of operations is a SQL statement.
From, Where, group by, having, order by, select
What is difference between aggregate and scalar functions? Examples?
Aggregate functions operate on a collection of values and return a single value while scalar functions return a single value based on input. Examples of aggregate are
count(), min(), max(), sum(), avg().
Examples of scalar are
ucase(), lcase(), round(), len()
JOINS
join, left, right, full,
SET OPERATIONS
union, union all, intersect, minus
union combines results of 2 or more select statements but doesnt include duplicates
union all same thing just includes duplicates
intersect only returns common
minus returns those only belonging to first set