Skip to main content

Featured

Space Explorers Book 7: Answers and Explanations

Memunic Space Explorers › Book 7: Memoon and the Search for Another Home › Answers and Explanations Answers and Explanations Habitable means life could live there; inhabited means life does live there. A world can be habitable and empty, as an unoccupied flat has a roof and water but nobody in it. The Moon has almost no air, so water would boil or freeze, and its gravity is only about one-sixth of Earth’s, too weak to keep air. Accept also: no greenhouse blanket, so it swings between very hot and very cold. Venus. It matches Earth in size and roughly in mass, but its thick carbon dioxide air traps heat, making it hot and crushing. “Twin” is only true for size and weight. A dip of 1 per cent means (planet width divided by star width) squared is 0.01, so the ratio is 0.1: the planet is about a tenth as wide as the star. Repeats at the same gap show the planet is going round the star in 12 days, and rule out a one-time event such as a passing object. A planet shines only by reflected l...

Byte by Byte Book 6: Chapter 11 – Databases and Records

Byte by Byte › Book 6: Python, Data and How Computers Work › Chapter 11: Databases and Records

Chapter 11: Databases and Records

You will learn: the difference between data and information, what a database and a DBMS are, how data is organised into tables, records and fields, how to choose data types and a primary key, how flat-file and relational databases differ, how to sort, filter and query data, and why databases must protect people's privacy.

🌟 The Adventure

Beautine had arrived in Pearlhaven full of excitement. "I'm wonderful at keeping things," she had announced. "I have stored nuts in more places than anyone in Memunic."

Two days later she was sitting in a mountain of scrolls in Octavia's records room, her bow askew and her tail drooping.

Since the web page went live, visitors had been pouring in: frogs from Riverbend, rabbits from Moonbrook in borrowed bubbles, owls from Snowpeak who refused to get wet and watched from boats. Octavia wrote every visitor on a scroll: name, home village, visiting day, and whether they wanted a tour of the Engine. Then she rolled up the scroll and put it on a shelf.

Now the mayor wanted to know how many visitors had come from Moonbrook, so he could send them a thank-you gift.

"I have to unroll every single scroll," wailed Beautine. "And some say Moonbrook, some say Moon Brook, and one just says the rabbits. There are two visitors called Finn and I can't tell if they're the same frog. And this one," she held up a soggy scroll, "has a day of the week but no name at all!"

Memoon looked at the shelves. Hundreds of scrolls, each one written differently, in no order. "You don't need more shelves," she said. "You need a database."

💡 Learn With Memoon

Data and information. Data is raw facts and figures with no meaning on their own: Moonbrook , 14 , Tuesday . Information is data that has been organised and processed so that it means something: 14 visitors came from Moonbrook on Tuesday. Computers store data. People and programs turn it into information.

What is a database? A database is an organised collection of data, stored electronically, so that it can be searched, sorted, updated and shared easily. The software used to create and manage a database is called a database management system (DBMS). Examples:

DBMSUsed for
Microsoft AccessSmall databases for offices and schools on Windows
LibreOffice BaseA free, open-source desktop database
MySQL, PostgreSQLWebsites and apps with millions of users
SQLiteInside almost every smartphone, storing app data such as contacts and messages

Whenever you book a train ticket, borrow a library book, buy something online or log in to a game, a database is working behind the scenes.

Problems with paper records. Octavia's scrolls show the classic problems a database solves:

ProblemExampleHow a database helps
Slow to searchUnrolling every scroll to find Moonbrook visitorsFind matching records in a fraction of a second
Inconsistent dataMoonbrook, Moon Brook, the rabbitsRules make data entered the same way every time
Duplicate dataThe same visitor written twiceA unique key for each record
Missing dataA scroll with no nameRequired fields cannot be left empty
Hard to shareOnly one person can read a scroll at onceMany users can use the database at the same time

Tables, records and fields. Data in a database is stored in tables. A table holds data about one kind of thing, such as visitors, books or students.

VisitorIDNameSpeciesVillageVisitDateTour
1FinnFrogRiverbend12-11-2026Yes
2HopRabbitMoonbrook12-11-2026No
3FinnFrogRiverbend13-11-2026Yes
4FrostOwlSnowpeak13-11-2026No
5CloverRabbitMoonbrook14-11-2026Yes
  • A field is one column: one piece of information about every item, such as Village. Each field has a field name at the top.
  • A record is one row: all the information about one item, here one visit. This table has 5 records and 6 fields.
  • Each box where a record and a field meet holds one value.

Notice that a table in a database looks a lot like a spreadsheet. The difference is in the rules: a database checks that every value in a field is the right type, that key values are unique, and that tables link together correctly.

Data types. Each field has a data type that controls what can be stored in it. This is a form of validation, and it lets the database sort and calculate correctly.

Data type (Access

StoresExample field

names)

Short TextLetters, digits and symbols, up to 255 charactersName, Village, Phone number
NumberNumbers for calculationsAge, Marks
Date/TimeDates and timesVisitDate
CurrencyMoney amountsTicketPrice
Yes/NoOne of two values (Boolean)Tour
AutoNumberA number the DBMS fills in automatically, 1, 2, 3...VisitorID

Phone numbers and PIN codes are stored as text, not numbers. You never do maths with them, and a number field would delete a leading zero.

The primary key. Look at records 1 and 3: two frogs called Finn from Riverbend. Are they the same frog visiting twice, or two different frogs? Names are not unique, so they cannot tell us. A database solves this with a primary key: a field whose value is unique for every record and is never empty. Here, VisitorID is the primary key. Real-world primary keys include your school roll number, a book's ISBN and the PNR number on an Indian Railways ticket.

Flat-file and relational databases. A database with just one table is a flat-file database. It is simple, but it repeats data. Imagine every record also storing the village's distance and the name of its leader: Riverbend, 12 km, Mayor Croak would be typed again for every Riverbend visitor. If the mayor changes, you would have to fix hundreds of records, and if you miss one, the data becomes inconsistent.

A relational database solves this by splitting the data into several tables that are linked together:

Villages table

VillageIDVillageNameDistanceKmLeader
V1Riverbend12Croak
V2Moonbrook20Luna
V3Snowpeak35Frost

Visitors table

VisitorIDNameSpeciesVillageIDVisitDateTour
1FinnFrogV112-11-2026Yes
2HopRabbitV212-11-2026No

Each village's details are now stored once. In the Visitors table, VillageID is a foreign key: a field that holds the primary key of a record in another table, creating the link, or relationship, between the two tables. Change Riverbend's leader in one place and every visitor record is automatically correct. Almost every large database in the world is relational.

Working with a database.

OperationWhat it doesExample
Add, edit, deleteChange the recordsAdd a new visitor; fix a spelling
SortArrange records in order by a field, ascending (A to Z, 0 to 9) or descendingVisitors by date, newest first
FilterShow only the records that match a condition, hiding the restOnly Moonbrook visitors
QueryAsk a question that can combine conditions, choose fields and use several tables; the answer can be saved and reusedNames of rabbits who wanted a tour in November
FormA friendly screen for typing in or viewing one record at a timeA visitor sign-in screen
ReportA neat, printable summary of dataVisitors per village this month

A glimpse of SQL. Large databases are queried with a language called SQL (Structured Query Language, often pronounced "sequel"). You will not need to write it yet, but you can already read it:

SELECT Name, VisitDate
FROM Visitors
WHERE Species = 'Rabbit' AND Tour = 'Yes'
ORDER BY VisitDate;

It means: show the name and visit date of every rabbit who wanted a tour, sorted by date. Notice the condition uses AND, just like Python.

Databases and privacy. Databases often hold personal data: names, addresses, phone numbers, photos, health records, marks. This data can be misused if it is leaked or stolen. Organisations must collect only what they need, keep it secure, use it only for the purpose they collected it for, and delete it when it is no longer needed. In India, the Digital Personal Data Protection Act, 2023 sets out rules like these. You have rights over your data too: be careful about which forms and apps you give your information to.

💡 Memoon’s tip: Before you build a table, decide your fields, their data types and the primary key on paper. Changing the design after hundreds of records have been entered is much harder.

Illustration from Byte by Byte Book 6: Chapter 11 – Databases and Records

✍️ Try It Yourself

Activity 1: Design a database on paper. Your class library needs a database. In your notebook:

  1. List at least six fields for a Books table, with a data type for each.
  2. Choose a primary key and explain why it is unique.
  3. Design a second table, Members, and decide how the two tables could be linked to record who has borrowed which book. What foreign key would you need?

Activity 2: A flat-file database in Excel.

  1. Open Excel and type these headings in row 1: VisitorID, Name, Species, Village, VisitDate, Tour.
  2. Type at least 12 records. Make up the data, include at least three villages, and include two visitors with the same name.
  1. Click any cell in your data and press Ctrl + T (or Insert → Table). Make sure My table has headers is ticked and click OK. Excel turns your data into a table with filter arrows.
  2. Sort: click the arrow on VisitDate and choose to sort oldest to newest.
  3. Filter: click the arrow on Village, untick Select All, and tick only one village. How many records are shown? (Look at the bottom left of the window.)
  4. Combine filters: keep the village filter and also filter Tour to show only Yes. This is like a simple query with AND.
  5. Clear the filters with Data → Clear.

Activity 3 (if your computer has Microsoft Access): A real DBMS.

  1. Open Access and choose Blank database. Name it Pearlhaven Visitors and click Create.
  2. Click Home → View → Design View. Name the table Visitors and click OK.
  3. The first field, ID, is already an AutoNumber primary key (look for the key icon). Rename it VisitorID .
  4. Add the fields Name (Short Text), Species (Short Text), Village (Short Text), VisitDate (Date/Time) and Tour (Yes/No).
  5. Click Home → View → Datasheet View, save when asked, and type at least eight records. Notice that Access fills in VisitorID for you and will not let you type words in the date field.
  6. Click Create → Query Design, add the Visitors table, and double-click Name, Village and Tour to add them. In the Criteria row under Village, type Moonbrook . Click Run (the red exclamation mark). You have written your first query.

(LibreOffice Base, which is free, works in a very similar way.)

Unplugged: The human database. Each person in your group writes a "record card" about themselves with these fields: first name, birth month, favourite colour, number of siblings, and how they come to school. Give everyone a unique ID number. Then answer these queries by sorting and filtering the cards: Who was born in June? Sort everyone by number of siblings. Who likes blue AND walks to school? Which field would make a bad primary key, and why?

🎉 Memoon Solves It

Memoon and Beautine spent the morning designing. On a slate they drew two tables, Visitors and Villages, and chose every field's data type. VisitorID would be an AutoNumber primary key. Village would no longer be typed at all: visitors would choose it from a list, so Moon Brook and the rabbits could never happen again. Name was made a required field.

Then came the hard part: turning the scrolls into records. Beautine, it turned out, was brilliant at this. She read each scroll, checked it against the ones already entered, and typed it in at astonishing speed. The two Finns were solved by asking the Riverbend frogs: there really were two different frogs called Finn, so they became VisitorID 1 and VisitorID 3, two separate records with two separate keys.

When the mayor arrived, Memoon ran a query. Village equals Moonbrook. Less than a second later the screen showed 47 records. "Forty-seven rabbits!" said the mayor. "Excellent. Forty-seven gifts." A second query showed that most visitors came on Saturdays, so the mayor decided to open the Engine tours on Saturdays only.

Beautine asked to be made Keeper of Records, and Octavia agreed at once. "For the first time in my life," said Beautine, smoothing her bow, "I know exactly where everything is."

As they celebrated, Pip arrived with her camera. "The mayor wants a poster for the Pearlhaven Open Days," she said, and showed them her photos of the Festival. In the best one, the Glow Wall looked wonderful, but a large grumpy pufferfish had swum right in front of it, and the whole picture was too dark.

❓ Check Your Knowledge

  1. What is the difference between data and information? Give an example.
  2. What is a DBMS? Name two.
  3. In a database table, what is a field and what is a record?
  4. Suggest a suitable data type for each field: Date of birth, Roll number in a class, Pocket money, Has a library card, Pincode, City.
  5. What is a primary key? Why can't Name be a good primary key?
  6. What is the difference between a flat-file database and a relational database?
  7. What is a foreign key?
  8. What is the difference between sorting and filtering?
  9. Give three places in everyday life where databases are used.
  1. Why should organisations collect only the personal data they really need?
  2. True or false: phone numbers should be stored in a Number field. Explain.
  3. Read this SQL and say in words what it does: SELECT Title FROM Books WHERE
Author = 'R. K. Narayan' ORDER BY Title;
  1. Challenge: A school stores every student's class teacher's name and phone number inside each student record. Explain the problems this causes, and redesign it as two linked tables, showing the primary and foreign keys.

📚 Word Bank

  • Data: raw facts and figures without meaning on their own.
  • Information: data that has been organised so that it has meaning.
  • Database: an organised collection of data stored electronically for easy searching and updating.
  • DBMS (database management system): software for creating and managing databases.
  • Table: a set of data about one kind of thing, arranged in rows and columns.
  • Field: a column in a table; one piece of information about each record.
  • Record: a row in a table; all the data about one item.
  • Data type: the kind of data a field can hold, such as text, number or date.
  • Primary key: a field whose value is unique for each record and never empty.
  • Flat-file database: a database with a single table.
  • Relational database: a database with several tables linked by keys.
  • Foreign key: a field that holds the primary key of a record in another table.
  • Relationship: the link between two tables.
  • Sort: arrange records in ascending or descending order.
  • Filter: show only the records that match a condition.
  • Query: a question asked of a database to find specific data.
  • Form: a screen for entering or viewing records.
  • Report: a formatted, printable summary of data.
  • SQL: Structured Query Language, used to query databases.
  • Personal data: information about an identifiable person.

Keep learning with Byte by Byte

Explore Book 6: Python, Data and How Computers Work. Find the ebook, purchase details and teaching slides on MemuniCity.

Watch this chapter on YouTube

Comments

Popular posts from this blog

CA-7 Job Status and Failure Reason Codes

Here are the various status codes that You may see for jobs in the Queue or Logs in CA-7. R-C0002 R-C0003 R-C0099 R-C0255 R-JCLER A-U0002 A-U0004 A-U0015 A-U0043 A-U4095 A-SOC7 A-U4000 Reason Code/Job Status Code explanation: The indication of the job's current disposition. Values and their meanings are: A-Snnnn-- The job has failed with a system abend. A-Unnnn --The job has failed with a user abend. C-Cnnnn --The job has completed successfully and is going through completion processing. E-ARFATT-- An error occurred during the attempt to attach ARF definitions. This can result if the ARFSET specified is not defined. A diagnostic message may have been written to the CA-7 log, the OS console, or to the trailer queue for the job (in which case it can be displayed using LQ,JOB=x,LIST=ALL). E-ARFERR ---The job encountered an error in the ARF processing. Do a LARFQ command for the job to get more specific information. E-SEGERR --The job has been requeued...

Whistling Winds and Waterfalls: 4 Days of Magic in Shillong

Nestled in the clouds, where the scent of pine trees mingles with the rhythm of waterfalls and the tunes of local guitar-strumming youth—Shillong is more than a place. It’s a vibe. If you’ve got 3 nights and 4 days, you’ve got just enough time to fall in love. Here’s how to make the most of it—food, fun, fog and fantastic views included. Day 1: Shillong, We’re Coming for You! You land in Guwahati, barely out of the airport when the hills start calling. You hop into your cab, Spotify on, windows down, and the three-hour ride to Shillong begins. Just when you think it can’t get better, you stop at Umiam Lake —a lake so calm, it looks like someone ironed the water. By evening, you’re sipping hot chai in Laitumkhrah, maybe nibbling on spicy momos or pork jadoh from a roadside stall. You’re checked into your charming hotel ( Tripura Castle if you fancy old-world royalty, Ri Kynjai if you’re into lakeside poetry). The breeze whispers secrets of waterfalls and pine forests. Sleep well, drea...

Installing and Configuring Hadoop on Ubuntu as a Pseudo Distributed Single Node Cluster

Briefly what is psuedo-distributed single node Hadoop cluster: It is a Hadoop distributed cluster having Single Node. All the five daemons (NN,DN,JT,TT,SNN) are running as individual JVM (java process) instances. We will get all distributed features of Hadoop. This mode is used to develop, test, and staging (before production) Map Reduce programs quickly. It writes all the system, daemon and user logs to different files on the cluster To install Hadoop in this mode, we have to modify the hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml. hadoop-env.sh contains all the Environment variables which are required for running Hadoop. All the default values are fine, Only we have to modify the JAVA_HOME=“The location of Java Home Directory” Core-site.xml contains all the cluster specific information like io, temp directory, sorting, file system uri etc. Hdfs-site.xml contains all the parameters which are specific to HDFS like name node directory, data node directory...