Chapter 15: Python and Databases Flashcards

1
Q

One of the values within a tuple. More commonly called a “column” or “field”.

A

attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When we tell the database to enforce a rule on a field or a row in a table. A common one is to insist that there can be no duplicate values in a particular field (i.e., all the values must be unique).

A

constraint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Allows you to execute SQL commands in a database and retrieve data from the database. Similar to a socket or file handle for network connections and files, respectively.

A

cursor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A piece of software that allows you to directly connect to a database and manipulate the database directly without writing a program.

A

database browser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A numeric key that points to the primary key of a row in another table. Establish relationships between rows stored in different tables.

A

foreign key

eg, artist_id (foreign key) in Track table links to id (primary key) in Artist table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Additional data that the database software maintains as rows and inserts into a table to make lookups very fast.

A

index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A key that the “outside world” uses to look up a particular row
eg. in a table of user accounts, a person’s email address might be a good candidate as one for the user’s data

A

logical key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Designing a data model so that no data is replicated. We store each item of data at one place in the database and reference it elsewhere using a foreign key.

A

normalization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A numeric key assigned to each row that is used to refer to rows in another table. Often the database is configured to automatically assign them as rows are inserted.

A

primary key

eg. id (primary key) in Artist table links to artist_id (foreign key) in Track table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An area within a database that contains tuples and attributes. More typically called a “table”.

A

relation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A single entry in a database table that is a set of attributes. More typically called “row”.

A

tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

SQL command that deletes the table and all of its contents from the database.
Can’t be undone

A

DROP TABLE
DROP TABLE IF EXISTS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

method to perform commands on database once cursor is implemented

A

.execute()
cur.execute(‘SQL KEYWORD table’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

SQL command to make a new table

A

cur.execute(‘CREATE TABLE table (column TYPE)’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

SQL command to query info from a database

A

SELECT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

SQL keyword to rename column or table

A

AS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

return unique values

A

DISTINCT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

filter results based on specified condition

A

WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

use with WHERE
match closely matching names using wildcard characters

A

LIKE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

use with WHERE
return results within a range.
Numbers: includes 2nd condition
Text: includes first specified character in 2nd condition

21
Q

use with WHERE
meets all conditions

22
Q

use with WHERE
meets any condition

23
Q

sorts results
ASC: default
DESC: high to low, Z-A

24
Q

specifies number of rows to return
always at end of query

25
if-then conditional CASE WHEN ... THEN ... ELSE ... END
CASE
26
creates a new table
CREATE TABLE
27
adds a new row to a table
INSERT INTO INSERT INTO table (columns)
28
edits table column(s)
ALTER TABLE
29
edits table row(s)
UPDATE
30
removes rows from a table needs WHERE clause to specify which rows
DELETE FROM
31
specifies how column can be used eg. data types
constraints
32
counts the number of rows
COUNT()
33
sum of the values in a column
SUM()
34
the largest / smallest value
MAX() / MIN()
35
the average of the values in a column
AVG()
36
round the values in a column
ROUND()
37
used with SELECT to arrange identical data into groups WHERE **answer** ORDER BY LIMIT
GROUP BY
38
use to filter groups GROUP BY **answer** ORDER BY LIMIT
HAVING
39
SQL keyword specifying row data to be inserted into table
VALUES 'INSERT INTO table (column1, column2) VALUES (?, ?)' , (values tuple)
40
SQL method that forces data to be written to the database file after editing
commit() eg. conn.commit()
41
SQL keyword used with UPDATE command to change data in table Similar to find and replace.
SET UPDATE table SET column = value
42
CRUD for INSERT INTO, SELECT, UPDATE, and DELETE FROM commands
Create Read Update Delete
43
SQL clause to extract data from multiple tables and combine. Used with ON condition to define how data is to be connected
JOIN SELECT title, plays, name, eyes FROM Track **JOIN** Artist ON Track.artist_id = Artist.id Joins artist data and track data
44
SQL command to automatically create primary keys
PRIMARY KEY (no value) CREATE TABLE table (id INTEGER PRIMARY KEY, other columns)
45
SQL method to check last automatically inserted primary key
SELECT last_insert_rowid()
46
SQL command to mark a logical key (text column) that tells the program to store extra information to look up that column faster
CREATE INDEX index_name ON table (column)
47
SQL constraint keyword to ensure no duplicates
UNIQUE CREATE UNIQUE INDEX
48
SQL command to insert a new record if the name is not already there
INSERT OR IGNORE INTO table (columns)
49
An intermediate table that functions as the "many" end in a many-to-one relationship between two other tables
junction / through / connector / join table CREATE TABLE Member ( user_id INTEGER, course_id INTEGER, **PRIMARY KEY (user_id, course_id)**)