Databases part 2 Flashcards

1
Q

Syntax to create a user defined type & inheritance? (OO SQL)

A

CREATE TYPE NameType AS (
firstName varchar(20),
lastName varchar(20)
) NOT FINAL; // Allows for sub typing

CREATE TYPE PersonType UNDER NameType (
gender varchar(20),
age int
) FINAL;

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

Syntax to create a Table & inheritance? (OO SQL)

A

CREATE TABLE person OF PersonType;

CREATE TABLE student OF UNDER person;

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

Syntax an array? (OO SQL)

A

authors varchar(20)[10]

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

Syntax an multiset? (OO SQL)

A

keywords varchar(20) multiset

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

What are the 3 ways to combine SQL with programs?

A

Stored procedures, interface libraries and embedded SQL.

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

Syntax for dynamic SQL in embedded SQL?

A

EXEC SQL PREPARE queryName FROM ;

EXEC SQL EXECUTE queryName;

// or you can execute in one statement:
EXEC SQL EXECUTE IMMEDIATELY ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Syntax for PHP/PDO query?

A
$db = new PDO($host, $user, $pw);
$result = $db->query("query text");
$index1 = $result->fetchColumn(0);
$index2 = $result->fetchColumn(1);
// to iterate over the results use:
while($row = $result->fetch()){
      echo '';
      for($row as $cell){
             echo " $cell ";
      }
      echo '';
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Syntax for PHP/PDO Anonymous Placeholder query?

A
$query = "SELECT * FROM Sells WHERE pub=? AND beer=?"
$stmt = $bd->prepare($query);
$pub = $_GET('pub'); $beer = "Coors";
$stmt->execute(array($pub, $beer));
$rows = $stmt->fetch();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Syntax for PHP/PDO Named Placeholder query?

A
$query = "SELECT * FROM Sells WHERE :pub AND :beer"
$stmt = $bd->prepare($query);
$pub = $_GET('pub'); $beer = "Coors";
$stmt->bindParam(:pub, $pub);
$stmt-> bindParam(:beer, $beer);
$rows = $stmt->fetch();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

3NF rules?

A

1 - Is the left hand side a superkey?
2 -If not a super key, is right hand side prime ( prime = attribute is part of key (not super key).

If not, violates 3NF.

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

BCNF rule?

A

R is in BCNF wrt F if for every FD X -> Y, X is a super key.

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