Databases Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

define: data

A

“known facts that can be recorded and have implicit meaning”

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

define: database

A

collection of related data

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

define: DBMS

A

acronym for DataBase Management System

a collection of programs that enables users to create and maintain a database with processes for creating and maintaining a database (that would otherwise be manually maintained)

These are the processes:
- defining (info type, structures, constraints)
- construction (process of storing data)
- manipulation (query, update, generate reports)
- sharing (between multiple users)

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

define: database system

A

database + DBMS

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

define: DBA

A

aka DataBase Administrator

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

define: persistent object

A

permanent

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

What does SQL stand for?

A

Structured Query Language

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

What is SQL?

A

programming language designed to manage data stored in relational databases

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

How does SQL operate?

A

through simple, declarative statements

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

Why does SQL operate through simple, declarative statements?

A

keeps data accurate and secure, and helps maintain the integrity of databases, regardless of size.

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

What is a relational database?

A

A database that organizes information into one or more tables

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

What is a table?

A

A table is a collection of data organized into rows and columns.

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

What’s another word for tables?

A

Tables are sometimes referred to as relations.

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

Identify the parts of this diagram in SQL terms

A

Refer to attached picture

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

How can you create a table from scratch?

Relation: celebs with properties
id (integer)
name
age (integer)

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

How do you insert a new row into a table? Given this data

1, Justin Beiber, 22
2, Beyonce Knowles, 33
3, Jeremy Lin, 27
4, Taylor Swift, 30

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

What’s the faster way to insert multiple rows into a table?

A
18
Q

What happens if we try to create a table with an existing name?

A

SQLite is case insensitive for most syntax
it will throw an error, because the table name already exists

https://discuss.codecademy.com/t/what-happens-if-we-try-to-create-a-table-with-an-existing-name/376312

19
Q

How do you return column ‘name’ from relation ‘celebs’?

A

SELECT name FROM celebs;

20
Q

What does SELECT statement do?

A

always return a new table called the result set

21
Q

How do you select all data from relation?

A

SELECT * FROM celebs;

22
Q

How would you add a new column to celebs table

twitter_handle
data type: text

A
23
Q

What is NULL?

A

A special value in SQL that represents missing or unknown data.

24
Q

Can we change the order a column is added to a table?

A

No. By default, a new column will always be added at the end of the table

however, you can always select the columns in any order
SELECT col3, col1, col2

source: https://discuss.codecademy.com/t/can-we-add-a-column-at-a-specific-position-to-a-table/376656

25
Q

How would you change Taylor Swift’s twitter handle to ‘@taylorswift13’ ?

A

UPDATE celebs
SET twitter_handle = ‘@taylorswift13’
WHERE id = 4;

  1. UPDATE is a clause that edits a row in the table.
  2. celebs is the name of the table.
  3. SET is a clause that indicates the column to edit.
26
Q

ALTER vs UPDATE statement

A

The ALTER statement is used to modify columns. With ALTER, you can add columns, remove them, or even modify them.

The UPDATE statement is used to modify rows. However, UPDATE can only update a row, and cannot remove or add rows.

https://discuss.codecademy.com/t/how-is-alter-different-from-update/376655

27
Q

How to delete existing records in the celebs table with no twitter_handle

A

DELETE FROM celebs
WHERE twitter_handle IS NULL;

28
Q

How do you delete only a certain number of rows?

A

DELETE FROM table
WHERE condition
LIMIT 5;

29
Q

What are constraints?

A

rules/restrictions around what kind of data type can be input into a table. Rejects data that doesn’t stick to the rules

30
Q

What does the PRIMARY KEY constraint do?

A

Uniquely identify the row.

Attempts to insert a row with an identical value to a row already in the table will result in a constraint violation which will not allow you to insert the new row.

31
Q

What does the UNIQUE constraint do?

A

UNIQUE columns have a different value for every row.

32
Q

PRIMARY KEY vs UNIQUE

A

A table can have many different UNIQUE columns, there can only be one PRIMARY KEY

33
Q

What does the NOT NULL constraint do?

A

NOT NULL columns must have a value.

Attempts to insert a row without a value for a NOT NULL column will result in a constraint violation and the new row will not be inserted.

34
Q

What does DEFAULT do?

A

DEFAULT columns take an additional argument that will be the assumed value for an inserted row if the new row does not specify a value for that column.

35
Q

How would you add the following constraints for the celebs table?

id is primary key
name is unique
date_of_birth must have a value
date_of_death must have a default value

A

CREATE TABLE celebs (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE,
date_of_birth TEXT NOT NULL,
date_of_death TEXT DEFAULT ‘Not Applicable’
);

36
Q

What command should you use to permanently remove a table from a database?

A

DROP TABLE

37
Q

When inserting, we need to check which constraint?

A

➢ that the candidate keys are not already present,
➢ that the value of each foreign key either
– is all NULL, or
– is all non-NULL and occurs in the referenced relation

38
Q

When deleting, we need to check which constraint?

A

referential integrity – check whether the primary key
occurs in another relation.

(slide 28, lec 2.1)

39
Q

define relational database schema

A

set of relation schema
{R1, . . . , Rm} and a set of integrity constraints.

(slide 31, lec 2.1)

40
Q

relational database instance is a

A

set of relation instances {r1, . . . , rm} such that each ri
is an instance of Ri, and the integrity constraints are satisfied.

(slide 31, lec 2.1)

41
Q
A