SQL: Part II
[Pages:31]SQL: Part II
Introduction to Database Management CS348 Spring 2021
Basic SQL features
? Query
? SELECT-FROM-WHERE statements ? Set/bag (DISTINCT, UNION/EXCEPT/INTERSECT (ALL)) ? Subqueries (table, scalar, IN, EXISTS, ALL, ANY) ? Aggregation and grouping (GROUP BY, HAVING) ? Ordering (ORDER) ? Outerjoins (and Nulls)
? Modification
? INSERT/DELETE/UPDATE
Lecture 4
? Constraints
2
Incomplete information
? Example: User (uid, name, age, pop) ? Value unknown
? We do not know Nelson's age
? Value not applicable
? Suppose pop is based on interactions with others on our social networking site
? Nelson is new to our site; what is his pop?
3
Solution 1
? Dedicate a value from each domain (type)
? pop cannot be , so use as a special value to indicate a missing or invalid pop
SELECT AVG(pop) FROM User;
SELECT AVG(pop) FROM User WHERE pop -1;
? Perhaps the value is not as special as you think!
? the Y2K bug
ges/y2k-ca rtoon.jpg
4
Solution 2
? A valid-bit for every column
? User (uid, name, name_is_valid, age, age_is_valid, pop, pop_is_valid)
SELECT AVG(pop) FROM User WHERE pop_is_valid;
? Complicates schema and queries
5
Solution 3
? Decompose the table; missing row = missing value
? UserName (uid, name) ? UserAge (uid, age) ? UserPop (uid, pop) ? UserID (uid)
? Conceptually the cleanest solution ? Still complicates schema and queries
? How to get all information about users in a table? ? Natural join doesn't work!
6
SQL's solution
? A special value NULL
? For every domain ? Special rules for dealing with NULL's
? Example: User (uid, name, age, pop)
?
7
Three-valued logic
TRUE = 1, FALSE = 0, UNKNOWN = 0.5 AND = OR = NOT =
? Comparing a NULL with another value (including another NULL) using , , etc., the result is NULL
? WHERE and HAVING clauses only select rows for output if the condition evaluates to TRUE
? NULL is not enough
? Aggregate functions ignore NULL, except COUNT(*)
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- sql part ii
- microsoft sql server 2005 how to create and restore
- processing big data with azure data lake
- sql create schema if not exists postgres
- tutorial 5 sql
- mysql how to create a website a guide for beginners
- dbs assignment i github pages
- databases constraints and triggers
- 084 2008 existential moments in database programming sas
- cs 348 introduction to database systems fall 2012
Related searches
- fidelity equity income ii fund
- global ii regents dbq
- aquaforno ii collapsible stove
- aquaforno ii amazon
- type ii demand ischemia
- level ii teaching certification pa
- virtual ba ii plus calculator
- ba ii plus calculator online
- english ii persuasive essay prompts
- texas instruments ba ii plus calculator
- ba ii plus user manual
- blackrock funds ii annual report