-
-
Notifications
You must be signed in to change notification settings - Fork 341
/
sql-quiz.ts
1366 lines (1365 loc) · 62.6 KB
/
sql-quiz.ts
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
const sqlQuiz = [
{
Question: "Which of the following is NOT a type of SQL constraint?",
Answer: "CHECKSIZE",
Distractor1: "PRIMARY KEY",
Distractor2: "FOREIGN KEY",
Distractor3: "UNIQUE",
Explanation:
"SQL constraints are used to specify rules for the data in a table. CHECKSIZE is not a standard SQL constraint. The standard constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and DEFAULT.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is a FOREIGN KEY constraint used for in SQL?",
Answer:
"A FOREIGN KEY constraint defines a relationship between tables by referencing the primary key of another table.",
Distractor1: "It ensures that a column can only contain numeric values.",
Distractor2: "It enforces uniqueness within a column.",
Distractor3: "It allows a column to contain NULL values.",
Explanation:
"A FOREIGN KEY constraint establishes a link between two tables by referencing the primary key of another table. It enforces referential integrity and helps maintain relationships between tables in a database.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is the purpose of the SQL INSERT statement?",
Answer:
"The SQL INSERT statement is used to add new records to a table in the database.",
Distractor1: "It is used to modify existing records in a table.",
Distractor2: "It is used to delete records from a table.",
Distractor3: "It is used to retrieve data from a table.",
Explanation:
"The INSERT statement is used to insert new records with specified values into a table, effectively adding data to the table.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is the purpose of the CREATE TABLE statement in SQL?",
Answer:
"The CREATE TABLE statement is used to create a new table in a database.",
Distractor1: "It is used to update existing table structures.",
Distractor2: "It is used to delete a table from the database.",
Distractor3: "It is used to add new records to an existing table.",
Explanation:
"The CREATE TABLE statement is used to define and create a new table in a database, specifying its columns, data types, and constraints.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is the purpose of the SQL WHERE clause?",
Answer:
"The SQL WHERE clause is used to filter and specify the records to be retrieved, updated, or deleted based on specific conditions.",
Distractor1: "It is used to order records in a table.",
Distractor2: "It is used to define the table's primary key.",
Distractor3: "It is used to join multiple tables together.",
Explanation:
"The WHERE clause is used to narrow down the selection of records in a table by applying specific conditions. It is commonly used with SELECT, UPDATE, and DELETE statements to filter records.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is SQL Injection?",
Answer:
"SQL Injection is when malicious SQL code is placed into input fields.",
Distractor1:
"SQL Injection is a method for improving SQL query performance.",
Distractor2: "SQL Injection is a way to add constraints to SQL queries.",
Distractor3: "SQL Injection is a tool used for creating SQL tables.",
Explanation:
"SQL Injection is a significant security concern as it allows attackers to bypass application security measures and manipulate database queries. They can extract, modify, or delete data, leading to unauthorized access or data breaches.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question:
"Which HTTP methods correlate with the CREATE, READ, UPDATE, and DELETE (CRUD) operations in SQL?",
Answer:
"HTTP POST corresponds to CREATE, HTTP GET to READ, HTTP PUT to UPDATE, and HTTP DELETE to DELETE (CRUD) operations.",
Distractor1:
"HTTP POST corresponds to DELETE, HTTP GET to CREATE, HTTP PUT to READ, and HTTP DELETE to UPDATE.",
Distractor2:
"HTTP POST corresponds to UPDATE, HTTP GET to DELETE, HTTP PUT to READ, and HTTP DELETE to CREATE.",
Distractor3:
"HTTP POST corresponds to READ, HTTP GET to UPDATE, HTTP PUT to DELETE, and HTTP DELETE to CREATE.",
Explanation:
"HTTP methods align with CRUD operations: POST (CREATE), GET (READ), PUT (UPDATE), and DELETE (DELETE). These methods are used to perform corresponding database operations.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What is the purpose of a PRIMARY KEY constraint in SQL?",
Answer:
"A PRIMARY KEY constraint uniquely identifies records within a table, and each table can have one primary key.",
Distractor1: "It specifies that a column can have NULL values.",
Distractor2: "It enforces the uniqueness of values in a column.",
Distractor3: "It allows multiple primary keys within a single table.",
Explanation:
"A PRIMARY KEY constraint ensures that the values in the specified column(s) are unique and not NULL. It uniquely identifies each record in the table and enforces data integrity.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question: "What does the NOT NULL constraint in SQL ensure?",
Answer:
"The NOT NULL constraint ensures that a column will not accept NULL values.",
Distractor1: "It enforces uniqueness of values in a column.",
Distractor2: "It allows a column to contain only unique values.",
Distractor3:
"It enforces a default value for a column if NULL is provided.",
Explanation:
"The NOT NULL constraint is used to specify that a column must contain a value and cannot be left empty (NULL). It ensures that every row in the table has a value in that column.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/"
},
{
Question:
"Which SQL database is known for its powerful features, open-source nature, and is often considered production-ready?",
Answer: "PostgreSQL",
Distractor1: "MySQL",
Distractor2: "Microsoft SQL Server",
Distractor3: "SQLite",
Explanation:
"PostgreSQL is known for its robust features and is often used in production environments.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter3constraints"
},
{
Question:
"Which SQL database is often used for learning and small systems due to its lightweight and serverless nature?",
Answer: "SQLite",
Distractor1: "MySQL",
Distractor2: "PostgreSQL",
Distractor3: "Microsoft SQL Server",
Explanation:
"SQLite is lightweight and great for learning and small systems.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter3constraints"
},
{
Question: "In SQL, how are boolean values typically stored in databases?",
Answer: "As integers (0 for false, 1 for true)",
Distractor1: "As text strings ('true' or 'false')",
Distractor2: "As binary data",
Distractor3: "As NULL values",
Explanation:
"Boolean values are commonly stored as integers, where 0 represents false and 1 represents true.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter3constraints"
},
{
Question:
"What is a common strategy for protecting against data loss when deleting records from a database?",
Answer: "Using soft deletes",
Distractor1: "Creating manual backups",
Distractor2: "Not allowing deletions",
Distractor3: "Using SQL injections",
Explanation:
"Soft deletes involve marking records as deleted instead of physically removing them, allowing for potential data recovery.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter3constraints"
},
{
Question: "In SQL,how many primary keys can be created in a table?",
Answer: "Only one",
Distractor1: "Infinte",
Distractor2: "Twelve",
Distractor3: "Two",
Explanation:
"A table can have multiple unique keys that identify each row, but only one primary key.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter3constraints"
},
{
Question: "In SQL, what does the HAVING clause typically follow?",
Answer: "GROUP BY",
Distractor1: "ORDER BY",
Distractor2: "WHERE",
Distractor3: "HAVING is used alone",
Explanation:
"The HAVING clause is used in combination with the GROUP BY clause to filter grouped records based on specified conditions.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter7howtoperformaggregationsinsql"
},
{
Question:
"In database normalization, what does the First Normal Form (1NF) require?",
Answer: "All attributes must have unique names",
Distractor1: "All data values in a column must be of the same data type",
Distractor2: "All primary keys must be integers",
Distractor3: " All attributes must have a value for every record",
Explanation:
"The First Normal Form (1NF) requires that all attributes in a table must have unique names, ensuring that each column represents a single atomic value.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter9databasenormalization"
},
{
Question:
"Which normal form ensures that there are no transitive dependencies?",
Answer: "Third Normal Form (3NF)",
Distractor1: "Second Normal Form (2NF)",
Distractor2: " Boyce-Codd Normal Form (BCNF)",
Distractor3: "Fourth Normal Form (4NF)",
Explanation:
"The Third Normal Form (3NF) addresses transitive dependencies and ensures that non-key attributes are not dependent on other non-key attributes.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter9databasenormalization"
},
{
Question:
"Which SQL clause is used to filter rows before applying the aggregate functions?",
Answer: "WHERE",
Distractor1: "GROUP BY",
Distractor2: "HAVING",
Distractor3: "ORDER BY",
Explanation:
"The WHERE clause in SQL is used to filter rows before applying the aggregate functions.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter7howtoperformaggregationsinsql"
},
{
Question:
"Which SQL clause sets the child data to NULL when the parent data is deleted?",
Answer: "ON DELETE SET NULL",
Distractor1: "UPDATE TO NULL ",
Distractor2: "ON DELETE CASCADE",
Distractor3: "DELETE NULL",
Explanation:
"SQL Server sets the rows in the child table to NULL if the corresponding rows in the parent table are deleted",
Link: "https://www.freecodecamp.org/news/sql-and-databases-full-course/"
},
{
Question: "In SQL, what does CRUD stand for?",
Answer: "CREATE, READ, UPDATE, DELETE",
Distractor1: "CREATE, ROW, UNION, DROP ",
Distractor2: "COPY, ROW, UPDATE, DISPLAY",
Distractor3: "COLUMNS, ROWS, UNION, DELETE",
Explanation:
"CRUD is an acronym that stands for CREATE, READ, UPDATE, and DELETE. These four operations are the bread and butter of nearly every database you will create.",
Link: "https://www.freecodecamp.org/news/a-beginners-guide-to-sql/#chapter4crudoperationsinsql"
},
{
Question:
"Which of the following best describes the role of the NEW keyword when working with triggers in SQL?",
Answer:
"It provides access to the new data being inserted or updated, allowing modification before the event if the trigger time is set to BEFORE.",
Distractor1: "It refers to the data after an UPDATE or DELETE operation.",
Distractor2: "It encrypts data before insertion.",
Distractor3: "It deletes old data when new data is inserted.",
Explanation:
"The NEW keyword provides access to the new data being created in INSERT and UPDATE events. When using BEFORE as the trigger time, the data can be modified before it is stored in the database.",
Link: "https://www.freecodecamp.org/news/sql-triggers/"
},
{
Question:
"How can you retrieve unique values from a specific column in SQL to avoid duplicates?",
Answer: "SELECT DISTINCT column_name FROM table_name;",
Distractor1: "DELETE DUPLICATE column_name FROM table_name;",
Distractor2: "REMOVE DUPLICATE column_name FROM table_name;",
Distractor3: "SELECT UNIQUE column_name FROM table_name;",
Explanation:
"The DISTINCT keyword in a SELECT statement retrieves only unique values from a particular column, effectively removing duplicates.",
Link: "https://www.freecodecamp.org/news/how-to-remove-duplicate-data-in-sql/"
},
{
Question: "What SQL command is used to delete a record from a table?",
Answer: "DELETE FROM",
Distractor1: "REMOVE FROM",
Distractor2: "DROP FROM",
Distractor3: "CUT FROM",
Explanation:
"The DELETE FROM command is used to remove records from a table in an SQL database. It's important to use a WHERE clause to specify which records to delete, otherwise all records will be removed.",
Link: "https://www.freecodecamp.org/news/how-to-perform-crud-operations-js-and-sql/"
},
{
Question: "Which of the following is not a commonly used SQL constraint?",
Answer: "UPDATE",
Distractor1: "CHECK",
Distractor2: "DEFAULT",
Distractor3: "UNIQUE",
Explanation:
"In SQL, the UPDATE statement is used to modify the existing records in a table and therefore not a constraint.",
Link: "https://www.freecodecamp.org/news/best-sql-database-tutorial/"
},
{
Question:
"In SQL, which of the following is the correct syntax for creating a table?",
Answer: "CREATE TABLE table_name (column1_name datatype, ...)",
Distractor1: "CREATE TABLE table_name (int main void column_name)",
Distractor2: "UPDATE TABLE table_name (column1_name datatype, ...)",
Distractor3: "CREATE NEW TABLE table_name (column1_name datatype, ...)",
Explanation:
"In SQL, tables are created by using the CREATE TABLE statement as well as specifying each columns datatype.",
Link: "https://www.freecodecamp.org/news/sql-create-table-statement-with-example-syntax/"
},
{
Question:
"In SQL, which command is used to convert from one data type to another?",
Answer: "CAST()",
Distractor1: "CHANGE()",
Distractor2: "TYPE()",
Distractor3: "CONVERT()",
Explanation:
"The CAST() function is used to convert a column in a table from one data type to another.",
Link: "https://www.freecodecamp.org/news/cast-a-function-in-sql-convert-char-to-int-sql-server-example/"
},
{
Question:
"In SQL, which of the following is the correct syntax for inserting a new record(row) into a table?",
Answer: "INSERT INTO table_name (column1, ...) VALUES (value1, ...);",
Distractor1: "ADD ROW table_name (column1, ...) VALUES (value1, ...);",
Distractor2: "ALTER table_name (value1, ...);",
Distractor3: "INSERT INTO table_name (column1, ...);",
Explanation:
"The INSERT INTO statement is used to add new rows into a table, with the number of values equal to the number of specified columns",
Link: "https://www.freecodecamp.org/news/insert-into-sql-how-to-insert-into-a-table-query-example-statement/"
},
{
Question:
"In SQL, what function is used to join two or more strings together to form a single string?",
Answer: "CONCAT()",
Distractor1: "SUBSTR()",
Distractor2: "INSERT()",
Distractor3: "JOIN()",
Explanation:
"The CONCAT() function joins at least two parameters(strings) and can accept a total of 254 parameters.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question:
"In relational databases, Primary keys cannot contain what type of value?",
Answer: "NULL values",
Distractor1: "string values",
Distractor2: "numeric values",
Distractor3: "boolean",
Explanation:
"Primary keys must contain unique values and cannot contain NULL values.",
Link: "https://www.freecodecamp.org/news/primary-key-sql-tutorial-how-to-define-a-primary-key-in-a-database/"
},
{
Question: "In SQL, what is a View?",
Answer:
"A View is a database object that presents data existing in one or more tables",
Distractor1: "A View removes an item from a table",
Distractor2: "A View sorts items in a table",
Distractor3: "A View does not exist in SQL",
Explanation:
"A View is a database object that presents data existing in one or more tables",
Link: "https://www.freecodecamp.org/news/sql-create-view-mysql/"
},
{
Question:
" In relational databases, which of the following allows you to uniquely identify a tuple?",
Answer: "Super Key",
Distractor1: "Schema",
Distractor2: "Attribute",
Distractor3: "Domain",
Explanation:
"Super Key is used to uniquely identify a tuple in a relation.",
Link: "https://en.wikipedia.org/wiki/Superkey"
},
{
Question:
"In SQL, how can the user change 'codingWebsite' into 'freeCodeCamp' in the 'Name' column for the Users table?",
Answer: "UPDATE Users Set Name='freeCodeCamp' WHERE Name='codingWebsite' ",
Distractor1:
"MODIFY Users Set Name = 'codingWebsite' WHERE Name = 'freeCodeCamp' ",
Distractor2:
"UPDATE Users Set Name = 'codingWebsite' WHERE Name = 'freeCodeCamp' ",
Distractor3:
"MODIFY Users Set Name = 'freeCodeCamp' WHERE Name = 'codingWebsite' ",
Explanation:
"The UPDATE command and WHERE clause are used together to change the name in a SQL table.",
Link: "https://www.freecodecamp.org/news/sql-update-statement-update-query-in-sql/"
},
{
Question:
"In MySQL, what is the maximum string length for the VARCHAR data type?",
Answer: "Up to 65,535 bytes",
Distractor1: "255 bytes",
Distractor2: "256 bytes",
Distractor3: "Up to 65,567 bytes",
Explanation:
"The VARCHAR data type has a maximum string length range from 0 to 65535.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question:
"Which command is used in a 'WHERE' or 'HAVING' clause to limit the selected rows to the items when a column has a certain pattern of characters contained in it?",
Answer: "LIKE",
Distractor1: "NOT",
Distractor2: "INSERT",
Distractor3: "JOIN",
Explanation:
"You can place NOT before LIKE to exclude the rows with the string pattern instead of selecting them.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "How do you limit query results in ORACLE-SQL?",
Answer: "FETCH FIRST",
Distractor1: "LIMIT",
Distractor2: "TOP",
Distractor3: "FIRST",
Explanation:
"You can use FETCH FIRST, in newer versions of Oracle, to restrict the number of rows returned by a query.",
Link: "https://www.freecodecamp.org/news/row_number-in-sql-select-top-example-in-sql-and-sql-server2/"
},
{
Question: "In a RDBMS, what is used to create a reference between tables?",
Answer: "Foreign Keys",
Distractor1: "Candidate Keys ",
Distractor2: "Alternate Keys",
Distractor3: "Composite Keys",
Explanation:
"A foreign key is used to link two tables by making reference to another table's primary key.",
Link: "https://www.freecodecamp.org/news/what-is-a-relational-database-rdbms-definition/"
},
{
Question:
"Which of the following MySQL commands shows the structure of a table?",
Answer: "DESCRIBE table_name;",
Distractor1: "SHOW table_name;",
Distractor2: "EXPLAIN table_name;",
Distractor3: "INFO table_name;",
Explanation:
"In MYSQL, the DESCRIBE command followed by the table name is used to show the structure of a table",
Link: "https://www.freecodecamp.org/news/learn-sql-queries-database-query-tutorial-for-beginners/"
},
{
Question:
"In SQL, how do you select every row in a given table named 'freeCodeCamp'?",
Answer: "SELECT * FROM freeCodeCamp",
Distractor1: "SELECT all FROM freeCodeCamp;",
Distractor2: "FROM freeCodeCamp SELECT all;",
Distractor3: "FROM freeCodeCamp SELECT *;",
Explanation:
"In SQL, SELECT is used to select data from a database. The * is a wildcard character that matches any column in the table. The FROM clause specifies the table to select from.",
Link: "https://www.freecodecamp.org/news/learn-sql-queries-database-query-tutorial-for-beginners/"
},
{
Question:
"In SQL, what keyword is used to count unique values that are NOT NULL and not duplicates?",
Answer: "DISTINCT",
Distractor1: "GROUP BY",
Distractor2: "COUNT",
Distractor3: "WHERE",
Explanation:
"In SQL, the DISTINCT keyword will only count unique values that are NOT NULL. The computer will ignore any duplicate values.",
Link: "https://www.freecodecamp.org/news/sql-distinct-statement-how-to-query-select-and-count/"
},
{
Question:
"In SQL, what keyword is used if the WHERE clause fails when being used with aggregate functions?",
Answer: "HAVING",
Distractor1: "ADD",
Distractor2: "DISTINCT",
Distractor3: "LIMIT",
Explanation:
"In SQL, you will have to use the HAVING clause because the WHERE clause fails when used with aggregate functions.",
Link: "https://www.freecodecamp.org/news/sql-having-how-to-group-and-count-with-a-having-statement/"
},
{
Question:
"Which of the following relational database management systems (RDBMS) should never be used to store data in a production app?",
Answer: "Microsoft Access",
Distractor1: "Microsoft SQL Server",
Distractor2: "MongoDB",
Distractor3: "PostgreSQL",
Explanation:
"Microsoft Access does not offer as much security, availability, and stability as SQL Server.",
Link: "https://en.wikipedia.org/wiki/Microsoft_Access"
},
{
Question:
"In SQL, what type of join returns rows that have a match in both tables?",
Answer: "INNER JOIN",
Distractor1: "FULL OUTER JOIN",
Distractor2: "RIGHT OUTER JOIN",
Distractor3: "LEFT OUTER JOIN",
Explanation:
"A INNER JOIN returns all rows for which there is a match in both tables.",
Link: "https://www.freecodecamp.org/news/the-ultimate-guide-to-sql-join-statements/"
},
{
Question: "In SQL, normalized databases are optimized to reduce...",
Answer: "Data redundancy",
Distractor1: "Read time",
Distractor2: "Query size",
Distractor3: "Storage space",
Explanation:
"Normalized databases are optimized to reduce data redundancy.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question:
"In SQL, which of the following is a wildcard character that can be used with the LIKE statement?",
Answer: "%",
Distractor1: "$",
Distractor2: "!",
Distractor3: "@",
Explanation:
"You can use the % and _ wildcards with the SQL LIKE statement to compare values from an SQL table.",
Link: "https://www.freecodecamp.org/news/sql-like-statement-how-to-query-sql-with-wildcard/"
},
{
Question:
"In SQL, what aggregate function allows you to count the number of rows and returns that count as a column in the result set?",
Answer: "COUNT()",
Distractor1: "AVG()",
Distractor2: "MINIMUM()",
Distractor3: "AVERAGE()",
Explanation:
"The COUNT() function is used to count the number of rows and return that count as a column in the result set",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "In SQL, what does DML stand for?",
Answer: "Data Manipulation Language",
Distractor1: "Data Definition Language",
Distractor2: "Data Control Language",
Distractor3: "Distracting Definition Language",
Explanation: "DML stands for Data Manipulation Language.",
Link: "https://en.wikipedia.org/wiki/Data_manipulation_language"
},
{
Question:
"In SQL, the column or set of columns that uniquely identifies each row in a table is known as a...",
Answer: "Primary Key",
Distractor1: "Secondary Key",
Distractor2: "First Key",
Distractor3: "Foreign Key",
Explanation:
"The primary key is the column or set of columns that uniquely identifies a row. ",
Link: "https://www.freecodecamp.org/news/the-sql-primary-key-constraint-explained/"
},
{
Question:
"In SQL, what statement is used to combine groups and aggregate data?",
Answer: "GROUP BY",
Distractor1: "UPDATE",
Distractor2: "CLASSIFY",
Distractor3: "CATEGORY",
Explanation:
"The GROUP BY statement is used to combine rows and aggregate data.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "Which one is NOT a type of data model used in NoSQL?",
Answer: "Infix notation",
Distractor1: "key-value",
Distractor2: "document",
Distractor3: "wide-column or tabular",
Explanation:
"NoSQL supports a variety of data models including 'key-value', 'document', 'wide-column or tabular' formats",
Link: "https://www.freecodecamp.org/news/learn-nosql-in-3-hours/"
},
{
Question: "What does DBMS stand for?",
Answer: "Database Management System",
Distractor1: "Dataset Management System",
Distractor2: "Database Maintenance System",
Distractor3: "Database Management Site",
Explanation: "DBMS stands for Database Management System. ",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question:
"In SQL, this is part of a query that determines which columns of data to show in the results.",
Answer: "SELECT",
Distractor1: "TABLE",
Distractor2: "CREATE",
Distractor3: "QUERY",
Explanation: "SELECT determines which columns will be shown in the result.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, an individual entry in a table of a database is known as...",
Answer: "Record/Row",
Distractor1: "Column",
Distractor2: "Cell",
Distractor3: "Query",
Explanation:
"An individual entry in a table of a database table is known as record or row.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question: "In SQL, what does DDL stand for?",
Answer: "Data Definition Language",
Distractor1: "Data Manipulation Language",
Distractor2: "Data Control Language",
Distractor3: "Deleting Definition Language",
Explanation: "DDL stands for Data Definition Language. ",
Link: "https://en.wikipedia.org/wiki/Data_definition_language"
},
{
Question:
"In SQL, what clause is used to limit the number of rows returned by a query based on specific criteria?",
Answer: "WHERE",
Distractor1: "LIMIT",
Distractor2: "FILTER",
Distractor3: "CHECK",
Explanation:
"The WHERE clause is used in SQL to limit the number of rows returned based on specific criteria.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "In SQL, the values of a table are known as...",
Answer: "Fields",
Distractor1: "API",
Distractor2: "Query",
Distractor3: "Database",
Explanation: "The values of a SQL database table are known as fields.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question:
"In SQL, what type of join returns all the records from the right table and the matching records from the left table?",
Answer: "RIGHT OUTER JOIN",
Distractor1: "LEFT OUTER JOIN",
Distractor2: "FULL OUTER JOIN",
Distractor3: "INNER JOIN",
Explanation:
"A RIGHT OUTER JOIN returns all the records from the right table and the matching records from the left table.",
Link: "https://www.freecodecamp.org/news/the-ultimate-guide-to-sql-join-statements/"
},
{
Question: "In SQL, what does DCL stand for?",
Answer: "Data Control Language",
Distractor1: "Data Manipulation Language",
Distractor2: "Data Definition Language",
Distractor3: "Data Concat Language",
Explanation: "DCL stands for Data Control Language.",
Link: "https://en.wikipedia.org/wiki/Data_control_language"
},
{
Question:
"In SQL, what is the command used to order the results in ascending or descending order?",
Answer: "ORDER BY",
Distractor1: "SORT BY",
Distractor2: "ASCENDING",
Distractor3: "DESCENDING",
Explanation:
"The ORDER BY command is used in SQL to sort the results in ascending or descending order.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question:
"In SQL, a computer programming language used for inserting, deleting, and updating data in a database is known as a...",
Answer: "Data Manipulation Language",
Distractor1: "Data Definition Language",
Distractor2: "Data Control Language",
Distractor3: "Data Storage Language",
Explanation:
"A computer programming language used for inserting, deleting, and updating data in a database is known as a Data Manipulation Language.",
Link: "https://en.wikipedia.org/wiki/Data_manipulation_language"
},
{
Question: "What is SQL?",
Answer: "A language used for relational databases",
Distractor1:
"A language that translates code from one languages to another",
Distractor2: "A language that converts data into machine code",
Distractor3: "A language used for non relational databases",
Explanation:
"SQL is used to store, manipulate, and retrieve data in relational database management systems. ",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question:
"In SQL, what command allows you to filter the data aggregated by the GROUP BY clause so that the user gets a limited set of records to view?",
Answer: "HAVING",
Distractor1: "LIMIT",
Distractor2: "QUERY",
Distractor3: "SELECT",
Explanation:
"The HAVING command allows you to filter the data aggregated by the GROUP BY clause so that the user gets a limited set of records to view.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, a structured set of data stored in a computer designed for efficient storage, retrieval, and maintenance is known as...",
Answer: "Database",
Distractor1: "Dataset",
Distractor2: "Query",
Distractor3: "Table",
Explanation:
"A database is a structured set of data stored in a computer designed for efficient storage, retrieval, and maintenance.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-explained-in-plain-english/"
},
{
Question:
"In SQL, what aggregate function allows you to calculate the average of a numeric column from the set of rows returned by a query?",
Answer: "AVG()",
Distractor1: "COUNT()",
Distractor2: "MINIMUM()",
Distractor3: "AVERAGE()",
Explanation:
"The AVG() function is used to calculate the average of a column from the set of rows returned by a query.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, what is the command used to change the structure of a table?",
Answer: "ALTER TABLE",
Distractor1: "CHANGE TABLE",
Distractor2: "UPDATE TABLE",
Distractor3: "MODIFY TABLE",
Explanation:
"The ALTER TABLE command is used to change the structure of a table in SQL.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "What does SQL stand for?",
Answer: "Structured Query Language",
Distractor1: "Standardized Question Language",
Distractor2: "String Query Language",
Distractor3: "Single Query Language",
Explanation:
"SQL stands for Structured Query Language and it is used with relational databases.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question: "In SQL, what is the command to create a table?",
Answer: "CREATE TABLE <table-name>",
Distractor1: "TABLE CREATE <table-name>",
Distractor2: "NEW TABLE <table-name>",
Distractor3: "TABLE NEW <table-name>",
Explanation:
"CREATE TABLE <table-name> is the SQL command to create a table. ",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, what command allows you to rename a column or table using an alias?",
Answer: "AS",
Distractor1: "ALIASES",
Distractor2: "SET",
Distractor3: "NAME",
Explanation:
"The AS command is used to rename a column or table using an alias.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, what type of join returns all rows for which there is a match in either of the tables?",
Answer: "FULL OUTER JOIN",
Distractor1: "RIGHT OUTER JOIN",
Distractor2: "LEFT OUTER JOIN",
Distractor3: "INNER JOIN",
Explanation:
"A FULL OUTER JOIN returns all rows for which there is a match in either of the tables.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, what type of join returns all the records from the left table and the matching records from the right table?",
Answer: "LEFT OUTER JOIN",
Distractor1: "FULL OUTER JOIN",
Distractor2: "INNER JOIN",
Distractor3: "RIGHT OUTER JOIN",
Explanation:
"A LEFT OUTER JOIN returns all the records from the left table and the matching records from the right table.",
Link: "https://www.freecodecamp.org/news/the-ultimate-guide-to-sql-join-statements/"
},
{
Question: "In SQL, what statement is used to update a record in a table?",
Answer: "UPDATE",
Distractor1: "CHANGE",
Distractor2: "SELECT",
Distractor3: "QUERY",
Explanation:
"The UPDATE statement is used to update the value of a record in SQL.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question:
"In SQL, what is the constraint used in SQL to limit the range of values that can be placed in a column?",
Answer: "CHECK",
Distractor1: "RANGE",
Distractor2: "RESTRICT",
Distractor3: "VALIDATE",
Explanation:
"The CHECK constraint is used to limit the range of values that can be placed in a column.",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "In SQL, what is the command used to delete a table?",
Answer: "DROP TABLE table_name",
Distractor1: "REMOVE TABLE table_name",
Distractor2: "DELETE TABLE table_name",
Distractor3: "ALTER TABLE table_name",
Explanation: "The DROP TABLE command is used to delete an entire table.",
Link: "https://www.freecodecamp.org/news/learn-sql-queries-database-query-tutorial-for-beginners/"
},
{
Question:
"In SQL, what is the command used to give a record a date and time value from the system on execution?",
Answer: "NOW()",
Distractor1: "TIMESTAMP()",
Distractor2: "Y-M-D()",
Distractor3: "DATETIME()",
Explanation:
"The NOW() function gives the selected record a value of the current timestamp",
Link: "https://www.freecodecamp.org/news/sql-date-functions-getdate/"
},
{
Question: "In SQL, where can we access all column names within a database?",
Answer: "INFORMATION_SCHEMA.COLUMNS",
Distractor1: "COLUMNS",
Distractor2: "SCHEMA.COLUMNS",
Distractor3: "SCHEMA.INFO.COLS",
Explanation:
"You can select from INFORMATION_SCHEMA.COLUMNS and combine with a WHERE clause when needing to identify where a certain column is stored.",
Link: "https://www.freecodecamp.org/news/learn-sql-queries-database-query-tutorial-for-beginners/"
},
{
Question:
"In SQL, what statement should you use to undo a GRANT statement?",
Answer: "REVOKE",
Distractor1: "UNDO",
Distractor2: "DELETE",
Distractor3: "ROLLBACK",
Explanation:
"The REVOKE statement can be used to undo the action of a GRANT statement.",
Link: "https://dev.mysql.com/doc/refman/5.6/en/revoke.html"
},
{
Question:
"In SQL, which command erases all the updates made from the start of the transaction?",
Answer: "ROLLBACK",
Distractor1: "COMMIT",
Distractor2: "DELETE",
Distractor3: "REVOKE",
Explanation:
"The ROLLBACK TRANSACTION command will erase all modifications made to the data. Changes made to table and local variables will not be affected by this command.",
Link: "https://learn.microsoft.com/en-us/sql/t-sql/language-elements/rollback-transaction-transact-sql?view=sql-server-ver16"
},
{
Question:
"Which of the following is not a distinct relationship in a SQL database?",
Answer: "All-to-one",
Distractor1: "One-to-one",
Distractor2: "One-to-many",
Distractor3: "Many-to-many",
Explanation:
"Database data can either be linked by one-to-one, one-to-many, or many-to-many relationships.",
Link: "https://www.freecodecamp.org/news/relational-vs-nonrelational-databases-difference-between-sql-db-and-nosql-db/"
},
{
Question:
"In SQL, which function rounds a number to a specified number of decimal places?",
Answer: "ROUND()",
Distractor1: "TRUNCATE()",
Distractor2: "CEIL()",
Distractor3: "FLOOR()",
Explanation:
"The ROUND() function takes in two parameters(number and decimals) and rounds the number to the number of decimals specified in the 2nd parameter.",
Link: "https://dev.mysql.com/doc/refman/5.7/en/precision-math-rounding.html"
},
{
Question:
"In SQL, which data type is used to store a string with up to 255 characters?",
Answer: "TINYTEXT",
Distractor1: "STRING",
Distractor2: "BLOB",
Distractor3: "BINARY",
Explanation:
"TINYTEXT can store up to 255 bytes and can be used for text like captions or summaries.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question: "In SQL, what does TCL stand for?",
Answer: " Transaction Control Language",
Distractor1: "Transaction controlling Language",
Distractor2: "Transacted Control Language",
Distractor3: "Transaction Console Language",
Explanation:
"Some of the Transaction Control Language commands include COMMIT, ROLLBACK, and SAVE TRANSACTION.",
Link: "https://www.freecodecamp.org/news/dbms-and-sql-basics/"
},
{
Question:
"In SQL, which of the following is an approach for joining tables?",
Answer: "All of the mentioned",
Distractor1: "Subqueries",
Distractor2: "Union Join",
Distractor3: "Natural Join",
Explanation:
"In SQL, you can use a subquery, union join or natural join to join multiple tables together.",
Link: "https://www.freecodecamp.org/news/dbms-and-sql-basics/"
},
{
Question:
"In SQL, what is the name of the join that will return matched and unmatched values from a table?",
Answer: "Outer join",
Distractor1: "All of the Mentioned",
Distractor2: "Equi-join",
Distractor3: "Natural Join",
Explanation:
"OUTER JOIN is used to return matched and unmatched values from a table.",
Link: "https://www.freecodecamp.org/news/dbms-and-sql-basics/"
},
{
Question:
"In SQL, what is the name for an organized collection of data kept in a central location?",
Answer: "Database",
Distractor1: "Table",
Distractor2: "Excel",
Distractor3: "csv",
Explanation:
"A database is a curated collection of structured data that is kept in one location.",
Link: "https://www.freecodecamp.org/news/sql-and-databases-full-course/"
},
{
Question:
"In MySQL, which of the following queries can be used to rename the table BaseCamp to BaseCamp_New?",
Answer: "ALTER TABLE BaseCamp RENAME TO BaseCamp_New ;",
Distractor1: "ALTER TABLE BaseCamp TO BaseCamp_New ;",
Distractor2: "ALTER TABLE BaseCamp UPDATE TO BaseCamp_New ;",
Distractor3: "ALTER TABLE BaseCamp SET TO BaseCamp_New ;",
Explanation:
"If you want to rename a table called BaseCamp to BaseCamp_New, then you would use the following syntax in MySQL: ALTER TABLE table_name RENAME TO new_table_name;",
Link: "https://www.freecodecamp.org/news/basic-sql-commands/"
},
{
Question: "In SQL, what does BLOB stand for?",
Answer: "Binary Large Object",
Distractor1: "Bad Listed Object",
Distractor2: "Bad Labelled Object",
Distractor3: "Big Listed Object",
Explanation:
"BLOB stands for Binary Large Object and it is a SQL data type used to store large amounts of data.",
Link: "https://www.freecodecamp.org/news/sql-data-types-mysql/"
},
{
Question: "In SQL, what are the two types of Database Management Systems?",
Answer: "relational databases and non-relational databases",
Distractor1: "functional and object oriented",
Distractor2: "procedural and relational",
Distractor3: "non-relational and assembly",
Explanation:
"The two types of Database Management Systems are relational and non-relational databases.",
Link: "https://www.freecodecamp.org/news/dbms-and-sql-basics/"
},
{
Question: "In SQL, which of these is not an aggregate function?",
Answer: "CAST",
Distractor1: "MIN/MAX",
Distractor2: "AVG",
Distractor3: "COUNT",
Explanation:
"Aggregate functions do a particular task across database rows. CAST is not an aggregate function because it is used to convert one type of data value into another.",
Link: "https://www.freecodecamp.org/news/sql-aggregate-functions-with-example-data-queries-for-beginners/"
},
{
Question: "In SQL, which of the following is not a DDL command?",
Answer: "DELETE",
Distractor1: "RENAME",
Distractor2: "TRUNCATE",
Distractor3: "COMMENT",
Explanation:
"DDL stands for Data Definition Language, but DELETE is a DML(Data Manipulation Language) command.",
Link: "https://www.freecodecamp.org/news/dbms-and-sql-basics/"
},
{
Question:
"In MySQL, which of the following would be used to delete a database named 'users'?",
Answer: "DROP DATABASE users",
Distractor1: "DELETE DATABASE users",
Distractor2: "TRUNCATE DATABASE users",
Distractor3: "UNDO DATABASE users",
Explanation:
"'DROP DATABASE <table-name>' drops all tables in the database and deletes the database.",
Link: "https://dev.mysql.com/doc/refman/8.0/en/drop-database.html"
},
{
Question: "In SQL, which of the following is a DQL command?",
Answer: "SELECT",
Distractor1: "UPDATE",
Distractor2: "COMMIT",
Distractor3: "INSERT",
Explanation:
"DQL stands for Data Query Language, and 'SELECT' is the only DQL command.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question: "In SQL, which of the following is not a string data type?",
Answer: "DEC",
Distractor1: "BLOB",
Distractor2: "BINARY",
Distractor3: "VARCHAR",
Explanation:
"DEC is a numeric data type while BLOB, BINARY and VARCHAR are string data types in SQL.",
Link: "https://www.freecodecamp.org/news/learn-sql-in-10-minutes/"
},
{
Question:
"In SQL, which of the following data types holds a FIXED length string?",
Answer: "CHAR",
Distractor1: "VARCHAR",
Distractor2: "TEXT",
Distractor3: "BLOBs",
Explanation:
"CHAR holds a fixed length string (up to 255 characters), while VARCHAR and TEXT hold variable length strings.",
Link: "https://www.freecodecamp.org/news/sql-data-types-mysql/"
},
{
Question:
"In SQL, which of the following wildcards combined with the LIKE operator finds any value that has 'or' at any position?",
Answer: "%or%",
Distractor1: "__r%",
Distractor2: "a__%",
Distractor3: "or%",
Explanation:
"The SQL LIKE operator with '%or%' matches any values containing 'or' at any position within the string.",
Link: "https://youtu.be/-fW2X7fh7Yg?t=5881/"
},
{