Databases part 2 Flashcards
Syntax to create a user defined type & inheritance? (OO SQL)
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;
Syntax to create a Table & inheritance? (OO SQL)
CREATE TABLE person OF PersonType;
CREATE TABLE student OF UNDER person;
Syntax an array? (OO SQL)
authors varchar(20)[10]
Syntax an multiset? (OO SQL)
keywords varchar(20) multiset
What are the 3 ways to combine SQL with programs?
Stored procedures, interface libraries and embedded SQL.
Syntax for dynamic SQL in embedded SQL?
EXEC SQL PREPARE queryName FROM ;
EXEC SQL EXECUTE queryName;
// or you can execute in one statement: EXEC SQL EXECUTE IMMEDIATELY ;
Syntax for PHP/PDO query?
$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 ''; }
Syntax for PHP/PDO Anonymous Placeholder query?
$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();
Syntax for PHP/PDO Named Placeholder query?
$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();
3NF rules?
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.
BCNF rule?
R is in BCNF wrt F if for every FD X -> Y, X is a super key.