Lecture 9- Other Features and Commands Flashcards

1
Q

What type of query is this?

emp(sin, name, phone, city)

A

INSERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What type of query is this?

emp(sin, name, phone, city)
Edmonton_phonebook(name, phone)

A

Bulk INSERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of query is this?

R(a1,…an)

A

DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What type of query is this?

R(a1,…,an)

A

UPDATE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is this query doing?

customer(cname, street, city)
deposit(accno, cname, bname, balance)

A

Insert a new customer record for John Smith who lives on 345 Jasper Ave, Edmonton

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is this query doing?

customer(cname, street, city)
deposit(accno, cname, bname, balance)

A

Delete all customers who have less than $1000 in their accounts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is this query doing?

customer(cname, street, city)
deposit(accno, cname, bname, balance)

A

Increase by 5% the balance of every customer who lives in Edmonton and has a balance of more than $5000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is VIEW?

A
  • View = query(~) = table
  • A derived table whose definition, not the table itself is sorted
  • Provides a degree of data independence
  • Queried like a table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create this query: create a view of customers who live in Jasper and name it Jasper customers

customer(cname, street, city)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create this query: list the names of all customers in Jasper

customer(cname, street, city)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In queries, ____ is exactly like a base table

A

A VIEW

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is this query doing?

customer(cname, street, city)
deposit(accno, cname, bname, balance)

A

Create a view (called cust info) which gives for each customer the name, city, the number of deposit accounts awned and the total balance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is this query doing?

customer(cname, street, city)
deposit(accno, cname, bname, balance)

A

Create a view (called deposit holders) which includes the name and the city of every deposit account holder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Views defined on ____ are generally not updatable

A

Multiple tables using joins

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A view defined on a single table is updatable if?

A

The view attributes contain the primary key or some other candidate key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Views defined using ____ are not updatable

A

Aggregate functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Each row and each column in an updatable view must?

A

Must correspond to a distinct row and column in a base table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

SQLite only supports?

A

Only supports read-only views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Give an example of left outer join

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Give an example of right inner join

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Give an example of full outer join

22
Q

Give an example of left outer join implementation in SQLite

23
Q

What is an alternative syntax to left outer join?

A
  • Join columns can have different names
  • More general conditions are possible
  • Two copies of column B
24
Q

When is an unknown null value useful?

A

Useful when we don’t know a column value

25
Q

Give some examples of queries that use null values

A
  • WHERE phone IS NULL
  • WHERE phone IS NOT NULL
  • SELECT cname FROM CUSTOMER WHERE city IS NOT NULL
26
Q

What are the three valued logics to use if the WHERE clause consists od several predicates?

A
  1. TRUE
  2. FALSE
  3. UNKNOWN
27
Q

What is a NULL value?

A
  • SQL uses NULL values to represent unknown/inapplicable values
  • The presence of NULL values complicates many issues (comparison using NULL values, using logical operators AND, OR, NOT, impacts of SQL constructs
28
Q

What operators to use to deal with unknown situations?

A
  • is NULL
  • is not NULL
29
Q

What are some set operations?

A
  • UNION
  • INTERSECT
  • EXCEPT
30
Q

By default, duplicates are removed from the result of a?

A

Set operation

31
Q

To keep duplicate use?

32
Q

What are some allowed integrity constraints?

A
  • Not null
  • Unique
  • Check(predicate)
33
Q

What are NOT NULL/Domain constraints?

A
  • Specifies that an attribute cannot contain null values
  • Should be specified for all primary keys (if its not default)
  • The NOT NULL constraint prohibits the insertion of NULL value for specified attribute
34
Q

Give an example of NOT NULL/Domain constraints

35
Q

What are UNIQUE constraints?

A
  • Specifies the alternate keys
  • It ensures that each value in a column or set of columns is unique across all rows in the table
  • Unlike the PRIMARY key constraint, a UNIQUE constrain allows NULL values
  • A table can have more than one UNIQUE constraint, unlike a PRIMARY key constrain where a table can have only one
36
Q

Give an example of a UNIQUE constraint

37
Q

What are CHECK constraints?

A
  • A common use of the CHECK clause is to ensure that attributes values satisfy specified conditions
  • The clause CHECK(P) specifies a predicate P that must be satisfied by every tuple in a relation
38
Q

Give an example of CHECK constraint

39
Q

Give an example of CREATE DOMAIN constraints

40
Q

What are domain constraints?

A

Specifies the condition that each row has to satisfy

41
Q

Give an example of a domain constraint

42
Q

What are tuple constraints?

A
  • Checked everytime a tuple is inserted or updated, violations are rejected
  • For when we want to set constraints for multiple fields
43
Q

What do you need before a tuple constraint?

A

Need the comma before a tuple constraint

44
Q

What type of constraint is this?

A

Tuple constraint

45
Q

What are assertions and why use them?

A
  • Global constraints of the form CREATE ASSERTION name CHECK (condition)
  • For when we want to set constraints over all tables (global constraint)
  • Before any insertions or update can be committed to the database perform the check and apply the specified condition
46
Q

Give an example of an assertion

47
Q

What are triggers in SQLite?

A
  • A set of actions available in the form of stored program
  • These set of actions are invoked automatically when certain actions occur
  • A trigger is created using the CREATE TRIGGER statement followed by the name of your trigger
48
Q

How do you use TRIGGER statements?

A
  • Make sure each trigger has a unique name
  • Next specify which table it must be assigned to
  • Specify the triggers logic, what it must acheive
  • If it requires multiple statements, then these must be enclosed within a BEGIN-END block
49
Q

Complete this task: Joe Smiths sales team are adding discounts to products, however, any discount over 25% must be reviewed by a manager

50
Q

What is this TRIGGER statement doing?

A
  • The purpose of this trigger is to log the old address information into an addressing table whenever there is a change in the address
  • This is creating a trigger called log-addresses
  • The trigger will activate after an UPDATE operation on the customer table
  • The trigger will only fire (execute) when there is a change in the street or city columns
  • If the stree or city changes the trigger will proceed
  • This inserts a new record into the addressing table, logging the details of the customers old and new addresses
51
Q

SQLite does not support updatable view, therefore ____ can be used instead