Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Exercises 21.15 Multiple Choice Questions
1.
Q-1: Looking at the code below, what would this line do?
INSERT INTO Cats (name, breed) VALUES ('Petunia', 'American Shorthair')
Add a table to the Cats database with the name "Petunia" and breed "American Shorthair".
Try Again! Inserts adds a row to a table.
Add a row to the Cats table with the name "Petunia" and the breed "American Shorthair".
Correct! This will insert a row in the table Cats with the name "Petunia" and the breed "American Shorthair".
Create the table Cats.
Try Again! This line wouldn't create a new table.
Add a row to the Cats table with the name "American Shorthair" and the breed "Petunia".
Try Again! Check the order of the columns and values.
2.
Q-2: Looking at the code below, what would this line do to the table Cats
?
cur.execute('DROP TABLE IF EXISTS Cats ')
It will remove the row "Cats".
Try again! "Cats" is not a tuple (row).
It will move "Cats" to the end of the database.
Try again! That's not quite what drop means in SQL.
It will remove the column "Cats".
Try again! "Cats" is not an attribute (column).
It will remove the table "Cats".
Correct! "Cats" is a relation (table), so this line will remove it from the database.
3.
Q-3: Which SQL keyword is used to combine rows from two tables in a database?
IN
Try again! The IN operator allows you to specify multiple values in a WHERE clause
JOIN
Correct! A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
BETWEEN
Try again! The BETWEEN operator selects values within a given range.
SELECT INTO
Try again! The SELECT INTO statement copies data from one table into a new table.
4.
Q-4: How can you delete all of the rows where the “name” is “Ruby” in the Cats Table?
DELETE FROM Cats WHERE name = 'Ruby'
Correct! This tells the program to remove all rows with a name equal to "Ruby" from the "Cats" table.
DELETE name='Ruby' FROM Cats
Try again! The table should be called first.
DELETE ROW name='Ruby' FROM Cats
Try again! You do not need to use the command "ROW". It will already delete the data associated with Ruby's entry.
DELETE FROM Cats WHERE name == 'Ruby'
Try again! You do not use == in SQL
5.
Q-5: Which of the following is not a SQL constraint?
UNIQUE
Try again! This constraint ensures that all values in a column are different
PRIMARY KEY
Try again! This constraint uniquely identifies each row in a table.
LOGICAL KEY
Correct! This is not a SQL constraint, because it is what *we* use to refer to a row, not the program's identifier.
NOT NULL
Try again! This constraint ensures that a column cannot have a NULL value.
6.
Q-6: Which command will try to remove data from a table in a database?
DELETE
Correct! Delete will try to remove data from a database.
REMOVE
Try Again! Remove is not a valid keyword for database.
COLLAPSE
Try Again! Collapse is not a valid keyword for a database.
DROP
Try Again! This is used to delete an entire table from a database.
7.
Q-7: Which is the correct command for a statement that will select data from the Breed column in the Cats table?
SELECT FROM Breed,Cats
Try again! The order of the commands and names are mixed up and no commas are necessary here!
SELECT Cats FROM Breed
Try again! The SELECT command should be followed by column name and the ROW command should be followed by a table name.
SELECT Breed FROM Cats
Correct! This command is very straight forward! It selects the breed from the table cats
FROM Cats SELECT Breed
Try again! The commands are in the wrong order. The SELECT command should come before the FROM command.
8.
Q-8: True or False? The following line will select all columns for the name “Bernard” from the table “Cats”.
SELECT * FROM Cats WHERE name = 'Bernard'
True
Correct! * indicates that you want the database to return all of the columns for each row that matches the WHERE clause.
False
Try again! What does the * indicate?
9.
Q-9: True or False? SQLite will not let two programs change the same data at the same time.
True
Correct! SQLite takes care to keep two programs from changing the same data at the same time, so make sure you save frequently!
False
Try again! You cannot change the same data at the same time on SQLite.
10.
Q-10: True or False? A cursor is used to create a database.
True
Try again! A connection is used to create a database, while a cursor is used to execute SQL commands on the database.
False
Correct! A cursor is used to execute SQL commands in a database and retrieve data from the database, not create one.