Functionally Dependent

basically is it a function same input must mean same output

Normal Forms

1NF - can every nonprime be derived from a portion of the key?

  • partial key (at least)

2NF - can every nonprime be derived only from the whole key?

  • whole

3NF - can every nonprime only be derived non-transitively?

  • Basically does every nonprime depend directly on the key?
  • transitivity

BCNF

  • ALL FD’s must have the superkey as the determinant (input/origin)
  • SUPERKEY ELITE

Decomposition

For whatever violates 3NF transitivity, turn it into its own relation (table)

Procedures

Loops

WHILE condition DO 
	operation;
END WHILE;

REPEAT 
	operation;
UNTIL condition;

Stored Procedures

DELIMITER //
CREATE PROCEDURE name(IN varName type, OUT varName2 type, INOUT varName3 type)
BEGIN
	DECLARE var INT;
	select count(*) into var from __;
	set varName2 = var;
END //


call name('value', @out, 'blah')

If Else

IF condition THEN
	operations;
ELSE
	operations;
ENDIF;

Use LEAVE labelName to leave an area of code on IF to leave a function

Functions

  • Must return single output
  • Can be used in queries, unlike SP
  • Cannot modify data, unlike SP
DELIMITER //
CREATE FUNCTION name(IN params)
DETERMINISTIC
BEGIN

END //