• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 8 pages
Summary

Summary SQL & Databases - Complete Study Guide

Document preview thumbnail
Preview 2 out of 8 pages

A complete original study guide for SQL and relational databases: SELECT, JOINs, aggregation, subqueries, CTEs, normalisation and transactions. Includes runnable query examples, exam traps and practice questions. Ideal for database courses and data interviews.

Content preview

SQL & Databases - Complete Study
Guide
SELECT, JOINs, aggregation, subqueries, normalisation and transactions - with
runnable examples




Complete Study Guide | Key Concepts | Examples | Practice Questions

, 1. Relational Model, Keys and Schema Design

A relational database stores data in tables (relations). Each row is a record, each column an attribute. Keys
enforce identity and relationships.

Key Meaning

Primary key Uniquely identifies each row; never NULL

Foreign key References a primary key in another table

Composite key Two+ columns together form the primary key

Candidate key Any column set that could be a primary key



CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE,
enrolled DATE DEFAULT CURRENT_DATE
);


CREATE TABLE enrollments (
student_id INT,
course_id INT,
grade CHAR(2),
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES students(id)
);



- NOT NULL, UNIQUE, CHECK and DEFAULT are column constraints.
- One-to-many is the most common relationship (one student, many enrollments).
- Many-to-many needs a junction table - like enrollments above.




Page 1

Document information

Uploaded on
October 2, 2026
Number of pages
8
Written in
2026/2027
Type
Summary
$5.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
25
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions