Skip to content

Commit 71fea05

Browse files
add Lecture006
1 parent cc420de commit 71fea05

File tree

7 files changed

+4336
-215
lines changed

7 files changed

+4336
-215
lines changed

db-course/004-Design-HW.ipynb

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,42 @@
3131
"3. If assignment has been graded, store the grade for each student and each assignment."
3232
]
3333
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"@schema\n",
41+
"class Student(dj.Manual):\n",
42+
" definition = \"\"\"\n",
43+
" student_id: int\n",
44+
" ---\n",
45+
" first_name : varchar(64)\n",
46+
" last_name : varchar(64)\n",
47+
" email : varchar(100) NOT NULL\n",
48+
" \"\"\"\n",
49+
"\n",
50+
"@schema\n",
51+
"class Assignment(dj.Manual):\n",
52+
" definition = \"\"\"\n",
53+
" assignment_id: int\n",
54+
" ---\n",
55+
" title: varchar(100)\n",
56+
" specification_link: varchar(255)\n",
57+
" due_date: date\n",
58+
" \"\"\"\n",
59+
"\n",
60+
"@schema\n",
61+
"class GradedAssignment(dj.Manual):\n",
62+
" definition = \"\"\"\n",
63+
" -> Student\n",
64+
" -> Assignment\n",
65+
" ---\n",
66+
" grade: decimal(5,2)\n",
67+
" \"\"\""
68+
]
69+
},
3470
{
3571
"cell_type": "markdown",
3672
"metadata": {},
@@ -45,6 +81,49 @@
4581
"5. Some books are not checked out."
4682
]
4783
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"@schema\n",
91+
"class BookTitle(dj.Manual):\n",
92+
" definition = \"\"\"\n",
93+
" isbn: varchar(13)\n",
94+
" ---\n",
95+
" title: varchar(255)\n",
96+
" author: varchar(255)\n",
97+
" \"\"\"\n",
98+
"\n",
99+
" \n",
100+
"@schema\n",
101+
"class Copy(dj.Manual):\n",
102+
" definition = \"\"\"\n",
103+
" -> BookTitle\n",
104+
" copy_id: int \n",
105+
" \"\"\"\n",
106+
"\n",
107+
"@schema\n",
108+
"class Member(dj.Manual):\n",
109+
" definition = \"\"\"\n",
110+
" member_id: int\n",
111+
" ---\n",
112+
" name: varchar(255)\n",
113+
" address: varchar(255)\n",
114+
" \"\"\"\n",
115+
"\n",
116+
"@schema\n",
117+
"class Checkout(dj.Manual):\n",
118+
" definition = \"\"\"\n",
119+
" -> Copy\n",
120+
" ---\n",
121+
" -> Member\n",
122+
" checkout_date: date\n",
123+
" return_date: date \n",
124+
" \"\"\""
125+
]
126+
},
48127
{
49128
"cell_type": "markdown",
50129
"metadata": {},
@@ -60,6 +139,101 @@
60139
"\n"
61140
]
62141
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"@schema\n",
149+
"class Branch(dj.Manual):\n",
150+
" definition = \"\"\"\n",
151+
" branch_id : int \n",
152+
" ---\n",
153+
" address : varchar(255) \n",
154+
" phone_number : varchar(12) \n",
155+
" \n",
156+
" \"\"\"\n",
157+
"\n",
158+
"@schema\n",
159+
"class Customer(dj.Manual):\n",
160+
" definition = \"\"\"\n",
161+
" customer_id : int \n",
162+
" ---\n",
163+
" address : varchar(255) \n",
164+
" phone_number : int \n",
165+
" first_name : varchar(255) \n",
166+
" last_name : varchar(255) \n",
167+
" dob : date\n",
168+
" number_of_accounts : int \n",
169+
" -> Branch.proj(home_branch=\"branch_id\")\n",
170+
" \"\"\"\n",
171+
"\n",
172+
"@schema\n",
173+
"class Account(dj.Manual):\n",
174+
" definition = \"\"\"\n",
175+
" account_id : int \n",
176+
" ---\n",
177+
" address : varchar(255) \n",
178+
" phone_number : int \n",
179+
" first_name : varchar(255) \n",
180+
" last_name : vbarchar(255) \n",
181+
" dob : date\n",
182+
" account_type : enum(\"savings\", \"checking\")\n",
183+
" -> Customer\n",
184+
" \"\"\""
185+
]
186+
},
187+
{
188+
"cell_type": "code",
189+
"execution_count": null,
190+
"metadata": {},
191+
"outputs": [],
192+
"source": [
193+
"@schema\n",
194+
"class Bank(dj.Manual):\n",
195+
" definition = \"\"\" \n",
196+
" bank_id: SMALLINT UNSIGNED\n",
197+
" ---\n",
198+
" bank_name: VARCHAR(30)\n",
199+
" \"\"\"\n",
200+
"\n",
201+
"@schema\n",
202+
"class HomeBranch(dj.Manual):\n",
203+
" definition = \"\"\" \n",
204+
" -> Bank\n",
205+
" branch_id: INT UNSIGNED\n",
206+
" ---\n",
207+
" street_address: VARCHAR(100)\n",
208+
" branch_phone: BIGINT\n",
209+
" bank_email: VARCHAR(100)\n",
210+
"\n",
211+
"\"\"\"\n",
212+
"\n",
213+
"@schema\n",
214+
"class Customers(dj.Manual):\n",
215+
" definition = \"\"\" \n",
216+
" -> HomeBranch\n",
217+
" customer_id: SMALLINT UNSIGNED\n",
218+
" ---\n",
219+
" first_name: VARCHAR(30)\n",
220+
" last_name: VARCHAR(30)\n",
221+
" date_of_birth: DATE\n",
222+
" customer_email: VARCHAR(100)\n",
223+
" phone: BIGINT UNSIGNED \n",
224+
"\"\"\"\n",
225+
"\n",
226+
"\n",
227+
"@schema\n",
228+
"class CustomerAccount(dj.Manual):\n",
229+
" definition = \"\"\" \n",
230+
" -> Customer\n",
231+
" account_num: BIGINT UNSIGNED\n",
232+
" ---\n",
233+
" account_type: ENUM('CHECKING','SAVINGS')\n",
234+
"\"\"\""
235+
]
236+
},
63237
{
64238
"cell_type": "markdown",
65239
"metadata": {},

0 commit comments

Comments
 (0)