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

A

BETWEEN

21
Q

use with WHERE
meets all conditions

A

AND

22
Q

use with WHERE
meets any condition

A

OR

23
Q

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

A

ORDER BY

24
Q

specifies number of rows to return
always at end of query

A

LIMIT

25
Q

if-then conditional
CASE
WHEN … THEN …
ELSE …
END

A

CASE

26
Q

creates a new table

A

CREATE TABLE

27
Q

adds a new row to a table

A

INSERT INTO

INSERT INTO table (columns)

28
Q

edits table column(s)

A

ALTER TABLE

29
Q

edits table row(s)

A

UPDATE

30
Q

removes rows from a table
needs WHERE clause to specify which rows

A

DELETE FROM

31
Q

specifies how column can be used
eg. data types

A

constraints

32
Q

counts the number of rows

A

COUNT()

33
Q

sum of the values in a column

A

SUM()

34
Q

the largest / smallest value

A

MAX() /
MIN()

35
Q

the average of the values in a column

A

AVG()

36
Q

round the values in a column

A

ROUND()

37
Q

used with SELECT to arrange identical data into groups
WHERE
answer
ORDER BY
LIMIT

A

GROUP BY

38
Q

use to filter groups
GROUP BY
answer
ORDER BY
LIMIT

A

HAVING

39
Q

SQL keyword specifying row data to be inserted into table

A

VALUES

‘INSERT INTO table (column1, column2) VALUES (?, ?)’ , (values tuple)

40
Q

SQL method that forces data to be written to the database file after editing

A

commit()

eg. conn.commit()

41
Q

SQL keyword used with UPDATE command to change data in table
Similar to find and replace.

A

SET
UPDATE table SET column = value

42
Q

CRUD for INSERT INTO, SELECT, UPDATE, and DELETE FROM commands

A

Create
Read
Update
Delete

43
Q

SQL clause to extract data from multiple tables and combine.
Used with ON condition to define how data is to be connected

A

JOIN

SELECT title, plays, name, eyes
FROM Track JOIN Artist
ON Track.artist_id = Artist.id
Joins artist data and track data

44
Q

SQL command to automatically create primary keys

A

PRIMARY KEY (no value)

CREATE TABLE table (id INTEGER PRIMARY KEY, other columns)

45
Q

SQL method to check last automatically inserted primary key

A

SELECT last_insert_rowid()

46
Q

SQL command to mark a logical key (text column) that tells the program to store extra information to look up that column faster

A

CREATE INDEX index_name ON table (column)

47
Q

SQL constraint keyword to ensure no duplicates

A

UNIQUE

CREATE UNIQUE INDEX

48
Q

SQL command to insert a new record if the name is not already there

A

INSERT OR IGNORE INTO table (columns)

49
Q

An intermediate table that functions as the “many” end in a many-to-one relationship between two other tables

A

junction / through / connector / join table

CREATE TABLE Member (
user_id INTEGER,
course_id INTEGER,
PRIMARY KEY (user_id, course_id))