21.14. Multiple Choice Questions¶
- Add a table to the Cats database with the name "Petunia" and breed "American Shorthair".
- Inserts adds a row to a table.
- Add a row to the Cats table with the name "Petunia" and the breed "American Shorthair".
- This will insert a row in the table Cats with the name "Petunia" and the breed "American Shorthair".
- Create the table Cats.
- This line wouldn't create a new table.
- Add a row to the Cats table with the name "American Shorthair" and the breed "Petunia".
- Check the order of the columns and values.
p9-1: Looking at the code below, what would this line do?
INSERT INTO Cats (name, breed) VALUES ('Petunia', 'American Shorthair')
- It will remove the row "Cats".
- "Cats" is not a tuple (row).
- It will move "Cats" to the end of the database.
- That's not quite what drop means in SQL.
- It will remove the column "Cats".
- "Cats" is not an attribute (column).
- It will remove the table "Cats".
- "Cats" is a relation (table), so this line will remove it from the database.
p9-2: Looking at the code below, what would this line do to the table
cur.execute('DROP TABLE IF EXISTS Cats ')
- The IN operator allows you to specify multiple values in a WHERE clause
- A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
- The BETWEEN operator selects values within a given range.
- SELECT INTO
- The SELECT INTO statement copies data from one table into a new table.
p9-3: Which SQL keyword is used to combine rows from two tables in a database?
- DELETE FROM Cats WHERE name = 'Ruby'
- This tells the program to remove all rows with a name equal to "Ruby" from the "Cats" table.
- DELETE name='Ruby' FROM Cats
- The table should be called first.
- DELETE ROW name='Ruby' FROM Cats
- 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'
- You do not use == in SQL
p9-4: How can you delete all of the rows where the “name” is “Ruby” in the Cats Table?
- This constraint ensures that all values in a column are different
- PRIMARY KEY
- This constraint uniquely identifies each row in a table.
- LOGICAL KEY
- This is not a SQL constraint, because it is what *we* use to refer to a row, not the program's identifier.
- NOT NULL
- This constraint ensures that a column cannot have a NULL value.
p9-5: Which of the following is not a SQL constraint?
- Delete will try to remove data from a database.
- Not quite.
- This is used to delete a table from a database.
p9-6: Which command will try to remove data from a table in a database?
- SELECT FROM Breed,Cats
- This has all the correct words, but they are quite mixed up. No commas are necessary here!
- SELECT Cats FROM Breed
- This uses the right order, but the wrong commands.
- SELECT Breed FROM Cats
- This command is very straight forward! It selects the breed from the table cats
- FROM Cats SELECT Breed
- This uses the right commands in the wrong order.
p9-7: Which is the correct command for a statement that will select data from the Breed column in the Cats table?
- * indicates that you want the database to return all of the columns for each row that matches the WHERE clause.
- Try again!
p9-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'
- SQLite takes care to keep two programs from changing the same data at the same time, so make sure you save frequently!
- Try again!
p9-9: True or False? SQLite will not let two programs change the same data at the same time.
- Try again!
- A cursor is used to execute SQL commands in a database and retrieve data from the database, not create one.
p9-10: True or False? A cursor is used to create a database.