SQL - Part 2 Flashcards

1
Q

What are the pros/cons of assertions, attribute/tuple checks, and triggers?

A

Assertions Pro: Powerful; Con: Don’t know when they need to be checked
Attribute/tuple Checks: Pro-checked at known times Con-not powerful
Triggers- Pro let use decide when to check, powerful; Con-complex!

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

What are the 3 criteria for triggers?

A

ECA:
Event-type of data base modification (insert on sells)
Condition: SQL boolean valued expression
Action- ANY SQL Statement

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

What are the 6 parts of trigger Syntax?

A

1 CREATE TRIGGER BeerTrig
2 AFTER INSERT ON SELL (event)
3 REFERENCING NEW ROW AS NewTuple
4 FOR EACH ROW
5 WHEN (NewTuple.beer NOT IN (SELECT name FROM Beers)) (condition)
6 INSERT INTO Beers(Name) VALUES NEwTuple.ber (action)

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

What is another option instead of CREATE TRIGGER?

A

REPLACE TRIGGER

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

What are the EVENT options?

A

AFTER/BEFORE/INSTEAD OF
INSERT/DELETE/UPDATE
(update may be on a particular attribute)

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

What are the REFERENCING options and when is it used?

A

REFERENCING [NEW OLD][ROW TABLE] AS

  • when inserting (use new)
  • when deleting (use old)
  • when updating (use both)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When is FOR EACH ROW used and what is an alternative?

A
  • indicates row-level; executed one for each modified tuple

- absence indicated statement-level; executed once for an SQL statement regardless of how many tuples are modified

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

What is the condition? How do I access the different tuples? When is it evaluated?

A

Any boolean-value condition (When tuple NOT IN (Select statement))

  • access the new/old tuples using the names in REFERENCING clause
  • evaluated before or after depending on event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the action? What if I have multiple?

A

SQL Statements that aren’t query; limited to modifications (insert, delete, update);
surround multiple by BEGIN..END

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

What to “modify” views?

A

Use INSTEAD OF Triggers

- turn insertion of a view into actual insertions

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

What are 3 differences between SQL triggers and Oracle Triggers?

A
  1. Action is a PL/SQL statement
  2. New/old tuples referenced automatically
  3. Stronger restrictions on trigger actions to avoid infinite sequence of triggers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are 3 kind of database modification?

A
  1. Insert tuples 2. Delete tuples 3. Update value of tuple(s)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the insertion syntax?

A
INSERT INTO Likes
VALUES ('Sally', 'Bud')
OR (specify attributes)
INSERT INTO Likes(beer, drinker)
VALUES ('Bud, 'Sally');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you insert using a subquery?

A

INSERT INTO PotBddfiers

(SELECT d2. drinker ..);

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

What is the deletion syntax? How to delete all tupels?

A

DELETE FROM WHERE ;

DELETE FROM ;

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

What are the stages of deletion?

A
  1. Mark tuples for WHERE condition is satisfied.

2. DELETE marked tuples

17
Q

What is the syntax for updates?

A

UPDATE
SET phone=’555’
WHERE name=’James’;

18
Q

What is the syntax to create a view?

A
CREATE VIEW  AS ;
CREATE VIEW CanDrink As
SELECT drinker
FROM Drinkers
WHERE drinks > 10;
19
Q

How do you access a view?

A

Same as base table; just can’t modify

20
Q

How does the DBMS interpret a view?

A
  1. Interpret query as if view was base table
  2. Turn query into relational algebra
  3. Transform definition of view by replacing algebraic equivalents
    Proj(view)
    Select
    Project (actual base table)
21
Q

What are the 2 key query optimizations?

A
  1. Push selection down tree

2. Elimination necessary projections