SQL Flashcards
(4 cards)
What are the 4 basic SQL queries?
- SELECT – Read data
- INSERT – Create data
- UPDATE – Modify data
- DELETE – Remove data
What types of relationships are possible in a relational database?
- One-to-One (1:1): Each record in Table A corresponds to exactly one record in Table B, and vice versa, e.g.
Users (id, name)
UserProfiles (user_id, bio, avatar_url) - One-to-Many (1:N): One record in Table A relates to many records in Table B, but each record in B relates to only one in A, e.g.
Authors (id, name)
Books (id, title, author_id) - Many-to-Many (M:N): Records in Table A can relate to many in Table B, and vice versa, e.g.
Students (id, name)
Courses (id, title)
Enrollments (student_id, course_id) – bridge table - Self-Referencing (Recursive): A row in a table can reference another row in the same table, e.g.
Employees (id, name, manager_id)
How would you describe the concept of database normalization to a non-developer?
Imagine you’re organizing customer information on paper.
- You start with one big sheet per customer that lists their name, orders, shipping address, and the products they bought.
- But you notice:
- The same customer’s info is repeated every time they buy something.
- Product details (like name and price) are copied over and over.
This wastes space, creates errors (typos, outdated info), and makes updating hard. So instead, you:
- Write customer details on one sheet.
- Write product details on another.
- Write orders on a third, linking to the customer and the product.
Now, if a customer changes their address, you only update it in one place. That’s normalization—you’re avoiding repetition, improving accuracy, and making everything more organized.
Normalization is the process of structuring a database to:
1. Eliminate redundant data
2. Ensure each piece of data lives in just one place
3. Make the database easier to update and maintain
How is data stored in a JSON database?
Each record (called a document) is a JSON object, and is stored as-is in the database. Documents are grouped into collections (similar to tables).
Features:
1. Schema-less: No fixed schema — each document can have different fields
2. Hierarchical: Nested objects and arrays are natively supported
3. Flexible: Easy to store complex and evolving data structures
4. Self-contained: All related data can be stored in a single document
5. Human-readable: Raw JSON can be viewed and understood directly