Relational databases, SQL, & modeling Flashcards
What is a primary key?
Primary key - The identifier for each row (often id).
What is a foreign key?
Foreign key - Data in one table that references a primary key in another table.
What is a one-to-many relationship? Provide an example.
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.
What is a many-to-many relationship? Provide an example.
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.
What are the SQL queries?
INSERT INTO
SELECT FROM
UPDATE
DELETE FROM
WHERE
How do you create a table using SQL queries?
CREATE TABLE ‘users-db’.’users’(
‘id’ INT NOT NULL AUTO_INCREMENT ,
‘username’ TEXT NOT NULL ,
‘email’ TEXT NOT NULL ,
PIMARY KEY (‘id’)
);
How do you select the row with id 1?
SELECT *FROM users WHERE id = 1;
How do you add new data using SQL queries?
Insert new row
INSERT INTO users (username, email)
VALUES (anna, anna.skog@mail.com);
What is a relational database?
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.