Naming a database and its tables

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Naming a database and its tables

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is a better name for a table that stores student records?
A Student Records!
B student
2. Which table name follows a naming convention with no spaces?
A class_room
B class room
3. A database has the tables student, teacher and subject. What is true about their names?
A They use different styles so each table stands out
B They use the same style: singular nouns in lower_case
4. Which table name uses a special character that should be avoided?
A order$item
B order_item
5. Which set of table names is named consistently?
A student, teacher, subject
B student, Teachers, SUBJECT_table

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1CREATE TABLE student AA singular, lower_case table name with no spaces
2CREATE DATABASE school_library Bstudent, class_room, teacher
3Table names should be singular nouns because each table describes one type of thing CA database name in lower_case that uses an underscore instead of a space
4Every table in the database uses the same style DThe table name contains a space, so it breaks the rule of no spaces. Use student_mark instead.
5CREATE TABLE Student Marks ECREATE TABLE teacher
6student, Teachers, class-room FThe names use mixed styles, a plural, and a special character (-). Use student, teacher, class_room instead.

Definitions

naming convention

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
CREATE TABLE _______ ( student_id INTEGER PRIMARY KEY );
2.
CREATE ________ school_records;
3.
CREATE _____ teacher (teacher_id INTEGER);
4.
INSERT INTO _______ (teacher_id) VALUES (1);
5.
CREATE DATABASE ______; USE school;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A CREATE DATABASE school db;
B CREATE TABLE student (
C student_id INT,
D name VARCHAR(50)
E );
Question 2
A CREATE DATABASE library;
B CREATE TABLE book (id INT);
C CREATE TABLE members (id INT);
D CREATE TABLE loan (id INT);
Question 3
A CREATE DATABASE shop;
B CREATE TABLE item (id INT);
C CREATE TABLE sale (id INT);
D CREATE TABLE staff# (id INT);
Question 4
A CREATE DATABASE tuck-shop;
B CREATE TABLE product (
C product_id INT,
D price DECIMAL(5,2)
E );
Question 5
A CREATE DATABASE school;
B CREATE TABLE class room (
C room_id INT PRIMARY KEY
D );

Answer Key

Naming a database and its tables
Section A: Quick Questions
Q1
B — student
Q2
A — class_room
Q3
B — They use the same style: singular nouns in lower_case
Q4
A — order$item
Q5
A — student, teacher, subject
Section B: Match the Pairs
Q1
CREATE TABLE student → A singular, lower_case table name with no spaces
Q2
CREATE DATABASE school_library → A database name in lower_case that uses an underscore instead of a space
Q3
Table names should be singular nouns because each table describes one type of thing → CREATE TABLE teacher
Q4
Every table in the database uses the same style → student, class_room, teacher
Q5
CREATE TABLE Student Marks → The table name contains a space, so it breaks the rule of no spaces. Use student_mark instead.
Q6
student, Teachers, class-room → The names use mixed styles, a plural, and a special character (-). Use student, teacher, class_room instead.
Section C: Definitions
Q1
naming convention — A consistent rule for naming a database and its tables, such as a singular noun in lower_case with no spaces or special characters, e.g. student, applied in the same style for every table.
Section D: Fill in the Blanks
Q1
CREATE TABLE student ( student_id INTEGER PRIMARY KEY );
Q2
CREATE DATABASE school_records;
Q3
CREATE TABLE teacher (teacher_id INTEGER);
Q4
INSERT INTO teacher (teacher_id) VALUES (1);
Q5
CREATE DATABASE school; USE school;
Section E: Spot the Error
Q1
A — A database name must not contain spaces. Use an underscore, as in school_db, so the name follows lower_case with no spaces.
Q2
C — Table names should be singular nouns like the others (book, loan). It should be member, not members.
Q3
D — Table names must not contain special characters such as #. It should be staff.
Q4
A — A hyphen is a special character and should not be used in a database name. Use an underscore: tuck_shop.
Q5
B — A table name cannot contain a space. It should be one word: classroom.