Computer Science Grade 10 20 min

Introduction to Databases: Storing Data

Introduce the concept of databases and basic SQL queries (SELECT, INSERT, UPDATE, DELETE).

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define what a database is and its purpose in a web application. Differentiate between a database, a table, a record (row), and a field (column). Explain the concept of a primary key and why it's essential for identifying unique records. Write a basic SQL `CREATE TABLE` statement to define a new table structure. Write a basic SQL `INSERT INTO` statement to add a new record to a table. Describe the relationship between a web form and a database table for storing user input. Identify common data types used in databases (e.g., INTEGER, TEXT, BOOLEAN). Ever wonder where your favorite game saves your high score or how a social media app remembers all your posts? 🎮 It's not magic, it's databases! In this lesson, we'll explore databases, t...
2

Key Concepts & Vocabulary

TermDefinitionExample DatabaseAn organized, structured collection of data stored electronically. Think of it as a container that holds all the information for an application.A school's database might contain tables for 'Students', 'Teachers', and 'Courses'. TableA collection of related data organized in a format of columns and rows. A database is usually composed of multiple tables.Within the school database, there would be a `Students` table to hold information only about students. Record (or Row)A single entry in a table, representing one complete item. It's a horizontal set of data.One row in the `Students` table that contains the ID, first name, last name, and grade for a single student like `(101, 'Alice', 'Smith', 10)`. Fie...
3

Core Syntax & Patterns

CREATE TABLE Syntax CREATE TABLE table_name (column1 datatype constraints, column2 datatype constraints, ...); Use this command to define the structure (schema) of a new table. You must specify the table name, the names of each column, and the type of data each column will hold (e.g., INTEGER, TEXT). INSERT INTO Syntax INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); Use this command to add a new record (row) of data into an existing table. The values you provide must match the order and data type of the columns you specify. Common Data Types INTEGER, TEXT, BOOLEAN, DATE These are fundamental types used to define what kind of data a column can store. `INTEGER` is for whole numbers, `TEXT` is for strings of characters, `BOOLEAN` is for true...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
Given the table `CREATE TABLE Users (UserID INTEGER PRIMARY KEY, Username TEXT);`, what happens if you execute the following two commands in order? `INSERT INTO Users (UserID, Username) VALUES (5, 'alex');` followed by `INSERT INTO Users (UserID, Username) VALUES (5, 'brian');`
A.Both commands will execute successfully, and there will be two users with UserID 5.
B.The first command will succeed, but the second will fail due to a primary key constraint violation.
C.The second command will overwrite the first user, changing the username from 'alex' to 'brian'.
D.Both commands will fail because the username must be unique.
Challenging
A developer needs to store user registration data from a web form. The form has fields for a username, an email, and a checkbox for 'Agree to Terms'. Which `CREATE TABLE` statement best models the required database structure?
A.CREATE TABLE Registrations (UserID INTEGER PRIMARY KEY, Username TEXT, Email TEXT, AgreedToTerms TEXT);
B.CREATE TABLE Registrations (UserID INTEGER PRIMARY KEY, Username TEXT, Email TEXT, AgreedToTerms BOOLEAN);
C.CREATE TABLE Registrations (Username TEXT, Email TEXT, AgreedToTerms BOOLEAN);
D.CREATE TABLE Registrations (UserID INTEGER, Username TEXT, Email TEXT, AgreedToTerms INTEGER);
Challenging
You need to store data for library books: a unique ID, title, author, publication year, and in-stock status. Which pair of `CREATE TABLE` and `INSERT INTO` statements is completely valid and correctly structured for this task?
A.CREATE TABLE Books (BookID INTEGER PRIMARY KEY, Title TEXT, Year INTEGER); INSERT INTO Books (BookID, Title, Year) VALUES (1, 'Dune', 1965);
B.CREATE TABLE Books (BookID TEXT, Title TEXT, Year INTEGER, InStock BOOLEAN); INSERT INTO Books VALUES (1, 'Dune', 1965, true);
C.CREATE TABLE Books (BookID INTEGER PRIMARY KEY, Title TEXT, PubYear INTEGER, InStock BOOLEAN); INSERT INTO Books (BookID, Title, PubYear, InStock) VALUES (1, 'Dune', 1965, TRUE);
D.CREATE TABLE Books (BookID INTEGER PRIMARY KEY, Title TEXT, PubYear INTEGER, InStock BOOLEAN); INSERT INTO Books (BookID, Title, InStock) VALUES (1, 'Dune', 'TRUE');

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Full-Stack Web Development: Building a Simple Web Application

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.