75/77
\begin{frame}[fragile]
  \frametitle{Foreign Key Constraints}
  
  \begin{code}{1\textwidth}{Foreign key constraints in SQL}
%###
\begin{verbatim}
create table Results ( 
  ...
  foreign key (sid) references Students(sid) 
)
\end{verbatim}
%###
  \end{code}
  \pause
  
  \begin{block}{}
    The \emph{foreign key constraint} ensures that
    \begin{itemize}
      \item [] for every tuple in $t \in \sql{Results}$ where $t.\sql{sid}$ is not \sql{null}, \\
               $\quad$ there exist a tuple $u \in \sql{Students}$ \\
               $\quad\quad$ such that $t.\sql{sid} = u.\sql{sid}$
    \end{itemize} 
  \end{block}
  
  \begin{alertblock}{}
    Foreign keys \textbf{may be null}, unless with \sql{not null} constraint.\\
    \remark{%
      This corresponds to a ``null'' pointer in programming languages.
    }
  \end{alertblock}
  \pause\smallskip
  
  \begin{goal}{}
    The \textbf{referential integrity} of the database
    is ensured by enforcing the foreign key constraints.
  \end{goal}
\end{frame}