Relational databases, SQL, & modeling Flashcards

1
Q

What is a primary key?

A

Primary key - The identifier for each row (often id).

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

What is a foreign key?

A

Foreign key - Data in one table that references a primary key in another table.

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

What is a one-to-many relationship? Provide an example.

A

One row in Table A connects to many rows in Table B and one row in table B connects to one row in Table A.
Ex: One person owns several cars, but each car has one owner.

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

What is a many-to-many relationship? Provide an example.

A

One row in Table A connects to many rows in Table B and one row in Table B connects to many rows in Table A.
Ex: One customer can purchase several products, each product can be purchased by several customers.

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

What are the SQL queries?

A

INSERT INTO
SELECT FROM
UPDATE
DELETE FROM
WHERE

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

How do you create a table using SQL queries?

A

CREATE TABLE ‘users-db’.’users’(
‘id’ INT NOT NULL AUTO_INCREMENT ,
‘username’ TEXT NOT NULL ,
‘email’ TEXT NOT NULL ,
PIMARY KEY (‘id’)
);

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

How do you select the row with id 1?

A

SELECT *FROM users WHERE id = 1;

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

How do you add new data using SQL queries?

A

Insert new row
INSERT INTO users (username, email)
VALUES (anna, anna.skog@mail.com);

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

What is a relational database?

A

A relational database organizes data into rows and columns, which collectively form a table. Data is typically structured across multiple tables, which can be joined together via a primary key or a foreign key. These unique identifiers demonstrate the different relationships which exist between tables, and these relationships are usually illustrated through different types of data models.

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