Structured Query Language (SQL)
Class 12 · Computer Science
4 ideas in Class 12 Computer Science, explained in plain words, with games and quizzes to practise.
Types Constraints and Creation
Part of: Building and changing tables
Every column needs a data type and may carry constraints. Fixed CHAR reserves its full width while variable VARCHAR uses only what the value needs. INT holds whole numbers, FLOAT holds decimals, and DATE holds calendar days. NOT NULL bans empties, UNIQUE bans repeats, DEFAULT fills gaps, PRIMARY KEY identifies rows, and FOREIGN KEY links tables. CREATE builds databases and tables, and DESCRIBE shows a table shape.
Why it matters. Right types save space and wrong ones corrupt meaning, like maths on phone numbers. Learners who declare types and constraints keep stores clean from the first row.
Key words
- Data Type
- : The kind of values a column may hold.
- CHAR
- : Fixed-width text that pads short values.
- VARCHAR
- : Variable text using only needed space.
- Constraint
- : A rule limiting what a column may hold.
- Primary Key
- : The column that uniquely identifies each row.
Try it in two minutes
- Compare storing city in fixed width ten versus variable width.
- Decide a type for prices, names and birth dates.
- Name the constraint that bans two pupils sharing one roll number.
Try at home. Ask your child to design a tiny book table with types and one primary key.
Altering Dropping Inserting Updating
Part of: Building and changing tables
ALTER reshapes a table by adding keys, columns, defaults or new widths, and by dropping what is unneeded. DROP removes a whole table or database forever. INSERT adds rows fully or partly, UPDATE rewrites values, and DELETE removes rows. Skipping the condition in UPDATE or DELETE strikes every row, so care is vital.
Why it matters. Stores evolve: new columns arrive and prices change. Learners who alter safely and always condition their writes avoid wiping whole tables by one slip.
Key words
- ALTER
- : Reshaping a table structure without remaking it.
- DROP
- : Removing a table or database permanently.
- INSERT
- : Adding new rows to a table.
- UPDATE
- : Rewriting values in existing rows.
- DELETE
- : Removing rows from a table.
Try it in two minutes
- Add a new column to a practice table.
- Update one row price with a tight condition.
- Predict what missing the condition would change.
Try at home. Ask your child to add a discount column to a toy table and fill two rows.
Selecting Filtering Ordering
Part of: Asking questions with SELECT
SELECT names the columns and FROM names the table, with an alias renaming a column for display. DISTINCT drops repeats, WHERE keeps only matching rows using ranges, lists and logic words, and ORDER BY sorts the answer. LIKE matches patterns where percent stands for any run and underscore for one character, and unknown values are tested with IS NULL.
Why it matters. Fetching exactly the needed rows in order is daily database work. Learners who filter and sort precisely answer real questions without drowning in full tables.
Key words
- SELECT
- : Fetching chosen columns from a table.
- DISTINCT
- : Dropping repeated values from the answer.
- WHERE
- : Keeping only rows that meet conditions.
- ORDER BY
- : Sorting the answer by chosen columns.
- LIKE
- : Matching text against letter patterns.
Try it in two minutes
- List all product names, then list them without repeats.
- Keep only rows priced between 50 and 130.
- Order the kept rows from dearest first.
Try at home. Ask your child to find all home items whose names start with one letter.
Functions Groups and Joins
Part of: Asking questions with SELECT
Single-row functions treat each row alone: power and rounding for numbers, case and length for text, and day parts for dates. Aggregate functions collapse groups into one value: maximum, minimum, average, sum and counts. GROUP BY forms the groups and HAVING filters them. UNION, INTERSECT and MINUS merge matching tables, cartesian pairing multiplies rows, and JOIN keeps only linked rows.
Why it matters. Totals, averages and grouped counts turn raw rows into business answers. Learners who group and join correctly build bills, reports and dashboards.
Key words
- Function
- : A ready task returning a value.
- Aggregate Function
- : Collapsing a group of rows into one value.
- GROUP BY
- : Collecting rows with alike values together.
- JOIN
- : Keeping only linked rows from two tables.
- UNION
- : Merging two matching tables without repeats.
Try it in two minutes
- Total the prices and find the dearest product.
- Group products by maker and count each group.
- Pair two clubs and keep only common members.
Try at home. Ask your child to total a grocery list and group items by shop section.
What your child will practise
- Altering Dropping Inserting Updating: Ocean Quick Fire (Quick Fire)
- Altering Dropping Inserting Updating: Space Puzzle (Clue Puzzle)
- Functions Groups and Joins: Ocean Puzzle (Clue Puzzle)
- Selecting Filtering Ordering: Jungle Puzzle (Clue Puzzle)
- Types Constraints and Creation: Jungle Quick Fire (Quick Fire)
- Quiz: Altering Dropping Inserting Updating (8 questions)
- Quiz: Functions Groups and Joins (8 questions)
- Quiz: Selecting Filtering Ordering (8 questions)
- Quiz: Types Constraints and Creation (8 questions)