{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ad8cb3d3",
   "metadata": {},
   "source": [
    "## Lecture 17 \n",
    "\n",
    "### Announcements\n",
    "\n",
    "- Homework #5 will be out later today, due thursday after exam#2\n",
    "  - You can solve it now or later the exam (though time is short). It is a great learning exercise\n",
    "  - You can submit it now or wait to see how you did in the exam if you are not sure if it is correct\n",
    "  \n",
    "  - I will provide some sample output, but I cannot guarantee if you will match it 100%. Let me know if you do.\n",
    "  \n",
    "- Lecture exercise #16 is out tomorrow at noon (the latest), due on sunday midnight.\n",
    "\n",
    "### Today's lecture\n",
    "\n",
    "- Triggers\n",
    "- Access control\n",
    "\n",
    "We will revisit the procedural paradigms shortly next week \n",
    "\n",
    "### Triggers\n",
    "\n",
    "- Become active on some action (insert/delete/update) on a table\n",
    "          "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1e6b476",
   "metadata": {},
   "source": [
    "\n",
    "   CREATE TRIGGER <triggername> \n",
    "         BEFORE/AFTER UPDATE/INSERT/DELETE on <table>\n",
    "      FOR EACH ROW\n",
    "      WHEN <condition>\n",
    "       BEGIN\n",
    "          <actions to take>\n",
    "       END ;\n",
    "            \n",
    "            \n",
    "- Example:  inserting a tuple  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf6912cc",
   "metadata": {},
   "source": [
    "            \n",
    "            \n",
    "            \n",
    "### ACCESS CONTROL      \n",
    "            \n",
    "- Database server (dbclass.cs.rpi.edu)\n",
    "   - Schema/namespace (public)\n",
    "   - Users/roles\n",
    "            \n",
    "- Roles is a set of users\n",
    "- A user may have many roles\n",
    "            \n",
    "CREATE ROLE dbclass ;  \n",
    "GRANT dbclass to adalis ;  \n",
    "GRANT dbclass to rattar ;  \n",
    "            \n",
    "CREATE ROLE dbta ;  \n",
    "GRANT dbta to rattar ;  \n",
    "-- REVOKE dbta from rattar ;  \n",
    "\n",
    "- Give access rights to individual roles or users\n",
    "\n",
    "GRANT CONNECT ON baking to dbclass ;  \n",
    "GRANT SELECT ON bakers to dbclass ;  \n",
    "GRANT INSERT ON bakers to dbta ;    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
