{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "035890f4-bee9-433a-aaff-520a3fabc100",
   "metadata": {},
   "source": [
    "# Create a Database Table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "61095f3c-0231-4ece-8b1d-d2a8af17b609",
   "metadata": {},
   "outputs": [],
   "source": [
    "from DATA225utils import make_connection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "34c69afc-ab9d-4235-bfb8-9936a7cbe56f",
   "metadata": {},
   "outputs": [],
   "source": [
    "conn = make_connection(config_file = 'personnel.ini')\n",
    "cursor = conn.cursor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "25c873fb-d77f-4287-9b65-04c603a78834",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('DROP TABLE IF EXISTS employee')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a0c2390b-f8c7-4598-bf93-a739d4c293c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "sql = ( \"\"\"\n",
    "        CREATE TABLE employee\n",
    "        (\n",
    "            id     int,\n",
    "            last   varchar(32),\n",
    "            first  varchar(32),\n",
    "            salary double,\n",
    "            PRIMARY KEY(id)\n",
    "        )\n",
    "        \"\"\"\n",
    "      )\n",
    "\n",
    "cursor.execute(sql)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47bdae54-46ee-467e-83a6-042d02687415",
   "metadata": {},
   "source": [
    "#### A `varchar` is a variable-length string, max 255.\n",
    "- If you want a `varchar` column to be the primary\n",
    "key, you must specify a maximum length.\n",
    "\n",
    "#### Common field datatypes:\n",
    "- int\n",
    "- double\n",
    "- varchar\n",
    "- date\n",
    "- time\n",
    "\n",
    "#### Link: [MySQL datatypes](https://www.javatpoint.com/mysql-data-types)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "694706e7-707d-4e7f-a49f-d9c13214c969",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.close()\n",
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5656bf2-3445-4253-a8df-d473e774cc20",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Copyright (c) 2023 by Ronald Mak"
   ]
  }
 ],
 "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.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
