Lecture 6- SQL Basics Flashcards
What are some features of SQL?
- Declarative = specify the properties that should hold in the result, not how to obtain the result
- Complex queries have procedural elements
- Set/Bag semantics
What is part of the data definition component?
- CREATE TABLE
- DROP TABLE
- ALTER TABLE (ADD, MODIFY, ADD constraint)
What is part of the data update component?
- INSERT INTO
- DELETE FROM
- UPDATE
What is SQL?
A query language
What is this query doing?
branch (bname, address, city, assets)
Find the names of all branches with assets greater than $2,500,000
What is this query doing?
branch (bname, address, city, assets)
Find the names of all branches in Edmonton with assets greater than $2,500,000
What is this query of two relations doing?
customer (cname, street, city)
deposit (accno, cname, bname, balance)
List the name and city of every customer who has an account with balance over $2,000
Write the query for this “find customers who have both loans and deposits” and what is the type of query?
loan (accno, cname, bname, amount)
deposit (accno, cname, bname, balance)
Queries with tuple variables
What is the evaluation strategy for this algorithm?
SELECT …
FROM R1 r1, R2 r2, …
WHERE C
- FROM clause produces cartesian product of listed tables
- WHERE clause produces table containing only rows satisfying condition
- SELECT clause retains listed columns
This is equivalent to what?
To get rid of duplicates we need to?
Use DISTINCT
Duplication elimination is not done ________ and must be _______
- Automatically
- Explicitly requested
Describe queries working with strings
- Equality and comparison operators apply to strings (based on lexical ordering) = Ex. WHERE cname < ‘P’
- Concatenate operator applies to strings = Ex. WHERE bname ||’–’|| address = …
- Expressions can also be used in SELECT clause = Ex. SELECT bname ||’–’|| address AS NameAdd FROM branch
What is partial matching?
Allows you to search for rows where a string column contains a certain pattern or portion of a string
Describe the LIKE operator
- Used to filter data based on pattern matching
- Patterns can be written using wildcard characters
- % = matches any sequence of characters (including zero characters)
- Underscore = matches exactly one character
- g _ % = matches values that start with letter g
This is an example of what?
Partial matching
These are examples of what?
Partial matching
What is this query looking for? (partial matching)
customer (cname, street, city)
Find every customer whose address starts with Computing Science