SQL Flashcards
SQL combines features of what 3 things?
- DDL (Data Definition Language)
- DML (Data Manipulation Language)
- DCL (Data Control Language)
DMC
What does CREATE TABLE statement do in SQL?
Defines a table schema, including:
* Attributes
* Constraints
* Default values
How does SQL handle NULL values?
Using three-valued logic: TRUE, FALSE, and UNKNOWN
What is the difference between PRIMARY KEY and UNIQUE?
- PRIMARY KEY: ensures uniqueness and non-null values for a single attribute
- UNIQUE: Allows nulls and can apply to multiple attributes
What is the purpose of the WHERE clause
Filter rows based on conditions in SELECT, UPDATE and DELETE statements
COUNT(*) vs COUNT(column)
‘*’ - counts all rows
column - Excludes NULL values in the specified column
What is an inner join?
Combines rows from two tables where there is a match on the join condition
Left Outer Join
Combines rows from two tables including all the rows from the first table, even if there is no match in the second. (NULLs in right table)
What is the purpose of the GROUP BY clause
Groups rows with identical values (in specified columns) for aggregate calculations
How does the HAVING clause differ from WHERE?
WHERE filters before aggregation, HAVING filters after aggregation
What is a view in SQL
Virtual table created by storing a query, dynamically evaluated each time it is referenced
Subquery vs CTE
- Subquery is embedded within another query
- CTE is temporary result set with a name, used for readability and reuse
Funcitonal dependency
Relationship where one attribute uniquely determines another
plantCode —> plantName
Main goals of normalization
- eliminate redundancy
- prevent anomalies
- ensure data consistency
DISTINCT
Removes duplicate rows from query result