Page 506 - Computer_Science_F5
P. 506
access to an online SQL editor (for The codes will look as follows:
example, W3Schools) CREATE TABLE crops (
3. Sample datasets for farming id INT PRIMARY KEY,
(optional for data entry exercises)
name VARCHAR(50) NOT NULL, Chapter Eight: Databases and Database Management Systems
FOR ONLINE READING ONLY
Instructions type VARCHAR(50) NOT NULL,
Create the database and table using planting_date DATE,
the following steps: harvest_date DATE,
Step 1: Create the “farming_ yield INT,
database” using the CREATE price DECIMAL(10, 2),
DATABASE statement. The farmer_id INT,
codes looks such as:
FOREIGN KEY (farmer_id)
CREATE DATABASE farming_database; REFERENCES farmers(id)
);
Step 2: Switch to this new database
using the USE statement. The above steps will set up the
The codes looks as: “farming_database” with the “farmers”
USE farming_database; and “crops” tables.
Step 3: Create the “farmers” table Deliverables
using the CREATE TABLE Write a comprehensive report that
statement, defining the include the following items:
columns and their data types. (a) SQL Script file: A file containing
The codes looks as: the SQL statements used to create
CREATE TABLE farmers ( the “farming_database”, “farmers”
id INT PRIMARY KEY, table, and “crops” table.
name VARCHAR(50) NOT NULL, (b) Database schema diagram: A
age INT, visual diagram illustrating the
location VARCHAR(100), relationships between the “farmers”
contact VARCHAR(20) and “crops” tables, including
); primary and foreign keys.
Step 4: Create the “crops” table, (c) Execution report: A document
including a “farmer_id” detailing the steps taken to
column that serves as a execute the SQL statements, with
foreign key referencing the screenshots or logs showing the
“id” column in the “farmers” creation of the database and tables.
table using the FOREIGN (d) Data entry examples (optional): If
KEY constraint. sample datasets were used, provide
497
Student’s Book Form Five
Computer Science Form 5.indd 497 23/07/2024 12:35

