-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
tutorial.json
3634 lines (3634 loc) · 127 KB
/
tutorial.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"id": "freeCodeCamp/learn-sql-by-building-a-student-database-part-1:v1.0.0",
"version": "3.0.0",
"summary": {
"title": "Learn SQL by Building a Student Database: Part 1",
"description": "> Welcome to the SQL Lessons!"
},
"config": {
"setup": {
"commands": [
"./.freeCodeCamp/reset.sh",
"cd .freeCodeCamp && npm install"
],
"commits": [
"d42669943ee7a32a8c38f907ed7914c91953f808"
]
},
"testRunner": {
"command": "npm run programmatic-test",
"args": {
"tap": "--reporter=mocha-tap-reporter"
},
"directory": ".freeCodeCamp"
},
"repo": {
"uri": "https://github.com/freeCodeCamp/learn-sql-by-building-a-student-database-part-1",
"branch": "v3.0.0"
},
"continue": {
"commands": [
"./.freeCodeCamp/reset.sh"
]
},
"reset": {
"commands": [
"./.freeCodeCamp/reset.sh"
]
},
"dependencies": [
{
"name": "node",
"version": ">=10"
}
],
"webhook": {
"url": "https://api.freecodecamp.org/coderoad-challenge-completed",
"events": {
"init": false,
"reset": false,
"step_complete": false,
"level_complete": false,
"tutorial_complete": true
}
}
},
"levels": [
{
"id": "10",
"title": "Start the Terminal",
"summary": "",
"content": "",
"steps": [
{
"id": "10.1",
"setup": {
"watchers": [
"../.bash_history"
],
"commits": [
"91fad900c0ccbbe1da8b2ec2986cba13b4ace2e4"
]
},
"content": "**The first thing you need to do is start the terminal.** Do that by clicking the \"hamburger\" menu at the top left of the screen, going to the \"terminal\" section, and clicking \"new terminal\". Once you open a new one, type `echo hello SQL` into the terminal and press enter.",
"hints": [
"Capitalization matters",
"If the tests don't run automatically, try typing `exit` into the terminal and redoing the instructions"
]
}
]
},
{
"id": "20",
"title": "psql login",
"summary": "",
"content": "",
"steps": [
{
"id": "20.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"6818ae581c459de5a23074aecc69027a1809c172"
]
},
"content": "You are started with two `.csv` files with info about your computer science students. You should take a look at them. The top row in each file has titles, and the rest are values for those titles. You will be adding all that info to a PostgreSQL database. Log into the psql interactive terminal with `psql --username=freecodecamp --dbname=postgres` to get started.",
"hints": [
"Type `psql --username=freecodecamp --dbname=postgres` into the terminal and press enter"
]
}
]
},
{
"id": "30",
"title": "\\l",
"summary": "",
"content": "",
"steps": [
{
"id": "30.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"ecacba1730230a0a9ae6bb224db9c90bb1548d98"
]
},
"content": "View the existing databases with the `\\l` shortcut command to see what's here.",
"hints": [
"Type `\\l` into the psql prompt and press enter"
]
}
]
},
{
"id": "40",
"title": "CREATE DATABASE students;",
"summary": "",
"content": "",
"steps": [
{
"id": "40.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"cb521b101a834362a8f100f5d3f6083ae2d08bc3"
]
},
"content": "All the info from the CSV files will go into a single database. Create a new database named `students`.",
"hints": [
"Use the `CREATE DATABASE` keywords",
"Here's an example: `CREATE DATABASE <database_name>;`",
"Type `CREATE DATABASE students;` into the psql prompt and press enter"
]
}
]
},
{
"id": "50",
"title": "\\l",
"summary": "",
"content": "",
"steps": [
{
"id": "50.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"3369962b4f22bee4939c0c2a427b16dad19ac3e1"
]
},
"content": "View the databases again to make sure it got created.",
"hints": [
"Use the **list** shortcut command in the psql prompt",
"Type `\\l` into the psql prompt and press enter"
]
}
]
},
{
"id": "60",
"title": "\\c students",
"summary": "",
"content": "",
"steps": [
{
"id": "60.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"cd8738e85c50167fe4444f4ef156ccd689278c2a"
]
},
"content": "There it is. Connect to your new database so you can start adding tables.",
"hints": [
"Use the `\\c` shortcut command",
"Here's an example: `\\c <database_name>`",
"Type `\\c students` in the psql prompt"
]
}
]
},
{
"id": "70",
"title": "CREATE TABLE students",
"summary": "",
"content": "",
"steps": [
{
"id": "70.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"e15a1087e5e57e8c0f6390ab52ad2fb83002bd5c"
]
},
"content": "The CSV files have a bunch of students with info about them, and some courses and majors. You will have four tables. One for the students and their info, one for each major, another for each course, and a final one for showing what courses are included in each major. First, create the `students` table.",
"hints": [
"Use the `CREATE TABLE` keywords",
"There should be parenthesis after the table name",
"Here's an example: `CREATE TABLE <table_name>();`",
"Type `CREATE TABLE students();` into the psql prompt"
]
}
]
},
{
"id": "80",
"title": "CREATE TABLE majors",
"summary": "",
"content": "",
"steps": [
{
"id": "80.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"19d00c78c84ace956628b8ad56dbfd8b8f8a3e7f"
]
},
"content": "The second table will be for each unique major that appears in the data. Create a table named `majors`.",
"hints": [
"Use the `CREATE TABLE` keywords",
"There should be parenthesis after the table name",
"Here's an example: `CREATE TABLE <table_name>();`",
"Type `CREATE TABLE majors();` into the psql prompt"
]
}
]
},
{
"id": "90",
"title": "CREATE TABLE courses",
"summary": "",
"content": "",
"steps": [
{
"id": "90.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"681614c9795683f083cd98c70d17b813c8f81fb2"
]
},
"content": "The third table is for each unique course in the data. Create another table named `courses`.",
"hints": [
"Use the `CREATE TABLE` keywords",
"There should be parenthesis after the table name",
"Here's an example: `CREATE TABLE <table_name>();`",
"Type `CREATE TABLE courses();` into the psql prompt"
]
}
]
},
{
"id": "100",
"title": "CREATE TABLE majors_courses",
"summary": "",
"content": "",
"steps": [
{
"id": "100.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"694c3459c7c3baf4ad177fe4c16ab53a9c9e427b"
]
},
"content": "The final table will be a junction table for the majors and courses. Create it with the name `majors_courses`.",
"hints": [
"Use the `CREATE TABLE` keywords",
"There should be parenthesis after the table name",
"Here's an example: `CREATE TABLE <table_name>();`",
"Type `CREATE TABLE majors_courses();` into the psql prompt"
]
}
]
},
{
"id": "110",
"title": "\\d",
"summary": "",
"content": "",
"steps": [
{
"id": "110.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"caf30db914db9212e6c742f7bc6e8c8cd3200e5d"
]
},
"content": "Use the **d**isplay shortcut command to view your tables to make sure your satisfied with them.",
"hints": [
"It's the `\\d` shortcut command",
"Type `\\d` in the psql prompt"
]
}
]
},
{
"id": "120",
"title": "Create student_id Column",
"summary": "",
"content": "",
"steps": [
{
"id": "120.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"3e8f9310559c2b1b0df72c7fdfeb056883f6e5aa"
]
},
"content": "Onto the columns. The `students.csv` file has four fields, you will make a column for each of those as well as an ID column. Add a column to your `students` table named `student_id`. Give it a type of `SERIAL` so it automatically increments and make it a `PRIMARY KEY`",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL` and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE students ADD COLUMN student_id SERIAL PRIMARY KEY;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "130",
"title": "Create first_name Column",
"summary": "",
"content": "",
"steps": [
{
"id": "130.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"e72cf140588235240e540c1a9fdbd6cd0d3de56c"
]
},
"content": "The first column in `students.csv` is `first_name`. Add a column to the `students` table with that name. Make it a type of `VARCHAR(50)` and give it the `NOT NULL` constraint.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()` and `NOT NULL` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE students ADD COLUMN first_name VARCHAR(50) NOT NULL;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "140",
"title": "Create last_name Column",
"summary": "",
"content": "",
"steps": [
{
"id": "140.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"9547bc4161879ae8c98c88255abb882e39d8ff3f"
]
},
"content": "The next column in the data is `last_name`. Add it to the `students` table. Give it the same data type and max-length as `first_name` and make sure it has the `NOT NULL` constraint.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()` and `NOT NULL` keywords",
"The max-length should be `50`",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE students ADD COLUMN last_name VARCHAR(50) NOT NULL;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "143",
"title": "Create major_id Column",
"summary": "",
"content": "",
"steps": [
{
"id": "143.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"dd9afa99c9b5e64d263dd9b423f83d1e7a5071d6"
]
},
"content": "The next column is for the major. Since you will have each major in another table this column will be a foreign key that references it. Create a column in the `students` table named `major_id`, give it a data type of `INT` for now. You will come back and set the foreign key later.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, and `INT` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE>;`",
"Type `ALTER TABLE students ADD COLUMN major_id INT;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "146",
"title": "Create gpa Column",
"summary": "",
"content": "",
"steps": [
{
"id": "146.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"06e08001970a2c6e9de25a7312d50a594997bb75"
]
},
"content": "Create the last column, `gpa`. The data in the CSV shows that they are decimals with a length of `2` and `1` number is to the right of the decimal. So give it a data type of `NUMERIC(2,1)`.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, and `NUMERIC()` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE>;`",
"Type `ALTER TABLE students ADD COLUMN gpa NUMERIC(2,1);` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "150",
"title": "\\d students",
"summary": "",
"content": "",
"steps": [
{
"id": "150.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"86b07f52f698d84ce2dc5cbbbfa177f82744be81"
]
},
"content": "Use the shortcut command to **d**isplay the details of the `students` table to make sure you like it.",
"hints": [
"It's the `\\d` shortcut command",
"Add the table name after the command",
"Here's an example: `\\d <table_name>`",
"Type `\\d students` in the psql prompt"
]
}
]
},
{
"id": "160",
"title": "Create major_id Column",
"summary": "",
"content": "",
"steps": [
{
"id": "160.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b6be18c4e019630ab5b1e236d5ccaff60b1f2f62"
]
},
"content": "The foreign key is still missing. Let's fill in the `majors` table next. Add a `major_id` column to it. Make it a type of `SERIAL` and the `PRIMARY KEY` for this table.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL` and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE majors ADD COLUMN major_id SERIAL PRIMARY KEY;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "170",
"title": "Create major Column",
"summary": "",
"content": "",
"steps": [
{
"id": "170.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"bfb05065f2d1bce73688d4d3f043a0966a29cc60"
]
},
"content": "This table will only have one other column for the name of the major. Add a column to it named `major`. Make it a `VARCHAR` with a max-length of `50` and give it the `NOT NULL` constraint.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()` and `NOT NULL` keywords",
"The max-length of `50` should go in the parenthesis of `VARCHAR`",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE majors ADD COLUMN major VARCHAR(50) NOT NULL;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "180",
"title": "\\d majors",
"summary": "",
"content": "",
"steps": [
{
"id": "180.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"8550d12cb225a62773f127d55bc617f14a714b9e"
]
},
"content": "View the details of the majors table to make sure you like it.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d majors` into the psql prompt"
]
}
]
},
{
"id": "183",
"title": "Create major_id foreign key",
"summary": "",
"content": "",
"steps": [
{
"id": "183.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"eda35deb2e83b38211df169e761d0fac1c293c86"
]
},
"content": "This table looks good. Now, set the `major_id` column from the `students` table as a foreign key that references the `major_id` column from the `majors` table. Here's an example of how to do that: `ALTER TABLE <table_name> ADD FOREIGN KEY(<column_name>) REFERENCES <referenced_table_name>(<referenced_column_name>);`",
"hints": [
"Type `ALTER TABLE students ADD FOREIGN KEY(major_id) REFERENCES majors(major_id);` in the psql prompt"
]
}
]
},
{
"id": "187",
"title": "\\d students",
"summary": "",
"content": "",
"steps": [
{
"id": "187.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"5b53a00b68e6bd25f9204d7acccf6fc505429fb1"
]
},
"content": "View the details of the `students` table again to make sure the key is there.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d students` into the psql prompt"
]
}
]
},
{
"id": "190",
"title": "Create course_id Column",
"summary": "",
"content": "",
"steps": [
{
"id": "190.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b57d2acc574fc72b281fe6579de7c7bc000ed715"
]
},
"content": "Next, is the `courses` table. Add a `course_id` column to it. Give it a type of `SERIAL` and make it the primary key.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL` and `PRIMARY KEY` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE courses ADD COLUMN course_id SERIAL PRIMARY KEY;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "200",
"title": "Create course Column",
"summary": "",
"content": "",
"steps": [
{
"id": "200.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"acc5f38d7a7bd34354ef974ce8ad6aa684822fc3"
]
},
"content": "Add a `course` column to the `courses` table that's a type of `VARCHAR`. The course names are a little longer, so give them a max-length of `100`. Also, make sure it can't accept null values.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()` and `NOT NULL` keywords",
"The max-length of `100` should go in the parenthesis of `VARCHAR`",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE> <CONSTRAINTS>;`",
"Type `ALTER TABLE courses ADD COLUMN course VARCHAR(100) NOT NULL;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "220",
"title": "\\d courses",
"summary": "",
"content": "",
"steps": [
{
"id": "220.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"a9c9c0077222bb94447f96ffbf110bde86143925"
]
},
"content": "View the details of the courses table to make sure it looks good.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d courses` into the psql prompt"
]
}
]
},
{
"id": "230",
"title": "Create major_id column",
"summary": "",
"content": "",
"steps": [
{
"id": "230.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"4373122ccf0274d09ac7d65078561955eca5c689"
]
},
"content": "One more table to go. The `majors_courses` junction table will have two columns, each referencing the primary key from two related table. First, add a `major_id` column to it. Just give it a type of `INT` for now.",
"hints": [
"Use the `ALTER TABLE`, `ADD COLUMN`, and `INT` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE>;`",
"Type `ALTER TABLE majors_courses ADD COLUMN major_id INT;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "240",
"title": "Set major_id Foreign Key",
"summary": "",
"content": "",
"steps": [
{
"id": "240.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"07fb92fb815e0876cef6f689514b7022f69e9187"
]
},
"content": "Set the `major_id` column you just created as a foreign key that references the `major_id` column from the `majors` table.",
"hints": [
"Use the `ALTER TABLE`, `ADD FOREIGN KEY`, and `REFERENCES` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD FOREIGN KEY(<column_name>) REFERENCES <referenced_table_name>(<referenced_column_name>);`",
"You previously used: `ALTER TABLE students ADD FOREIGN KEY(major_id) REFERENCES majors(major_id);`",
"Type `ALTER TABLE majors_courses ADD FOREIGN KEY(major_id) REFERENCES majors(major_id);` into the psql prompt"
]
}
]
},
{
"id": "250",
"title": "Create course_id Column",
"summary": "",
"content": "",
"steps": [
{
"id": "250.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"caddd78d843df82e5ec68212110b004b445b6d54"
]
},
"content": "Next, add a `course_id` column to the same table. Just give it a type of `INT` again for now.",
"hints": [
"It goes in the `majors_courses` table",
"Use the `ALTER TABLE`, `ADD COLUMN`, and `INT` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD COLUMN <column_name> <DATA_TYPE>;`",
"Type `ALTER TABLE majors_courses ADD COLUMN course_id INT;` into the psql prompt",
"You can drop a column with `ALTER TABLE <table_name> DROP COLUMN <column_name>;` if you want to delete a column and try again"
]
}
]
},
{
"id": "260",
"title": "Set course_id Foreign Key",
"summary": "",
"content": "",
"steps": [
{
"id": "260.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"3d2656daae4aead799844c94c81f2963a79f8b53"
]
},
"content": "Set your new `course_id` column as a foreign key that references the other `course_id` column.",
"hints": [
"The referenced column is `course_id` from the `courses` table",
"Use the `ALTER TABLE`, `ADD FOREIGN KEY`, and `REFERENCES` keywords",
"Here's an example: `ALTER TABLE <table_name> ADD FOREIGN KEY(<column_name>) REFERENCES <referenced_table_name>(<referenced_column_name>);`",
"You previously used: `ALTER TABLE students ADD FOREIGN KEY(major_id) REFERENCES majors(major_id);`",
"Type `ALTER TABLE majors_courses ADD FOREIGN KEY(course_id) REFERENCES courses(course_id);` into the psql prompt"
]
}
]
},
{
"id": "270",
"title": "\\d majors_courses",
"summary": "",
"content": "",
"steps": [
{
"id": "270.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"f72431860666ecbf3d8104e4611216dd5015f572"
]
},
"content": "View the details of the table you just worked on to make sure the structure is finished.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d courses` into the psql prompt"
]
}
]
},
{
"id": "280",
"title": "Create Composite Primary Key",
"summary": "",
"content": "",
"steps": [
{
"id": "280.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b4afdd32d77db0423f40df2b76889803ab8cb7d8"
]
},
"content": "There's one thing missing. This table doesn't have a primary key. The data from `courses.csv` will go in this table. A single major will be in it multiple times, and same with a course. So neither of them can be a primary key. But there will never be a row with the same two values as another row. So the two columns together, are unique. You can create a composite primary key that uses more than one column as a unique pair like this: `ALTER TABLE <table_name> ADD PRIMARY KEY(<column_name>, <column_name>);` Add a composite primary key to the table using the two columns.",
"hints": [
"It's the `major_id` and `course_id` columns from the `majors_courses` table",
"Type `ALTER TABLE majors_courses ADD PRIMARY KEY(major_id, course_id);` into the psql prompt"
]
}
]
},
{
"id": "290",
"title": "\\d majors_courses",
"summary": "",
"content": "",
"steps": [
{
"id": "290.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"ad1f306c52df65047b5faff257152f41ba33e9cd"
]
},
"content": "View the details of the table again.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d courses` into the psql prompt"
]
}
]
},
{
"id": "300",
"title": "\\d",
"summary": "",
"content": "",
"steps": [
{
"id": "300.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"14b12c3580b2209607a10e2baa56874bed89981e"
]
},
"content": "Okay, now it's finished. View all the tables you ended up with.",
"hints": [
"Use the **d**isplay shortcut command",
"Don't include a table name after the command",
"It's the `\\d` command",
"Type `\\d` into the psql prompt"
]
}
]
},
{
"id": "310",
"title": "\\d majors",
"summary": "",
"content": "",
"steps": [
{
"id": "310.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"661d6141c3dd090b8c454cbbad24e8f37ab6dbbc"
]
},
"content": "Next, you can start adding some info. Since the `students` table needs a `major_id`, you can add a major first. View the details of the `majors` table to see what info it expects.",
"hints": [
"Use the **d**isplay shortcut command",
"Add the table name after the command",
"It's the `\\d` command",
"Here's an example: `\\d <table_name>`",
"Type `\\d majors` into the psql prompt"
]
}
]
},
{
"id": "320",
"title": "INSERT INTO majors",
"summary": "",
"content": "",
"steps": [
{
"id": "320.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"f7f24fb1077488fc0dcf13b4f464a97834d385f2"
]
},
"content": "It only needs the name of a major. The ID will be added automatically. Add the first major from the `courses.csv` file into the `majors` table. It's a `VARCHAR`, so make sure to put the value in single quotes.",
"hints": [
"The major is `Database Administration`",
"Use the `INSERT INTO` and `VALUES` keywords",
"Here's an example: `INSERT INTO <table_name>(<column_name>) VALUES(<value>);`",
"Type `INSERT INTO majors(major) VALUES('Database Administration');`"
]
}
]
},
{
"id": "340",
"title": "SELECT * FROM majors",
"summary": "",
"content": "",
"steps": [
{
"id": "340.1",
"setup": {
"watchers": [
"../pg.log"
],
"commits": [
"94ecf58cf1bfacbf721a60856da4c8d8f41faa81"
]
},
"content": "Use `SELECT` to view all the data in the `majors` table to make sure it got inserted correctly.",
"hints": [
"Use the `SELECT` and `FROM` keywords with `*` to view all the columns",
"Here's an example: `SELECT <columns> FROM <table_name>;`",
"Type `SELECT * FROM majors;` into the psql prompt"
]
}
]
},
{
"id": "350",
"title": "INSERT INTO courses",
"summary": "",
"content": "",
"steps": [
{
"id": "350.1",
"setup": {
"watchers": [
"../queryResults.log"
],
"commits": [
"b046ea329944bda1a6918c4a957b3d5e919f8e31"
]
},
"content": "Next, insert the first course from `courses.csv` into the `courses` table.",