Page 507 - Computer_Science_F5
P. 507

Computer Science  (e) Reflection summary:  A brief   Step 1: Create an index
                examples of data entries for the
                “farmers” and “crops” tables.
                                                      Add an index to the ‘name’ column
                                                      in the ‘crops’ table  to speed up data
                                                      retrieval operations, the code looks as:
                summary reflecting on the
          FOR ONLINE READING ONLY
                experience, any challenges faced
                during the activity, and what was      CREATE INDEX idx_crops_name ON
                learned from creating and managing     crops(name);
                the SQL database.                     This statement creates an index called
                                                      “idx_crops_name”  on the “name”
            Finally, make sure you document your      column in the “crops” table. Indexes
            work in a portifolio.
                                                      improve  the  speed  of  data  retrieval
                                                      operations on specific columns.
                  Activity 8.24:
                                                      Step 2: Create a view
             Creating an index and view in SQL        Create a view to combine data from
                                                      the “farmers” and “crops” tables based
            Aim:                                      on their relationship, codes look as:
            To learn how to optimise data retrieval    CREATE VIEW crop_farmer_
            using indexes and how to create a          information AS
            view to combine and display related         SELECT c.id AS crop_id, c.name
            data  from  multiple  tables  in  a  SQL         AS crop_name, c.planting_date,
            database.                                        c.harvest_date, c.yield, c.price,

            Materials                                        f.id AS farmer_id, f.name AS
             1.  Computer with Internet access               farmer_name, f.age, f.location,
                                                             f.contact
             2.  SQL database management system
                (such as MySQL, PostgreSQL)             FROM crops c
             3.  SQL client software or an online       JOIN farmers f ON c.farmer_id = f.id;
                SQL editor (e.g., phpMyAdmin,         Note:  This statement  creates a view
                MySQL Workbench, or an online         named    “crop_farmer_information”
                platform like W3Schools)              that combines data from the “crops”

             4.  Sample dataset for the “farmers”     and  “farmers”  tables.  The  view
                and “crops” tables                    includes columns from both tables and
            Instructions                              joins the data based on the “farmer_
                                                      id” foreign key relationship.
            To add an index to a column in the
            “crops” table and create a view based     Deliverables
            on the data in the database, follow       Write a comprehensive report
            these steps:                               including the following:


                                                 498
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   498                                                     23/07/2024   12:35
   502   503   504   505   506   507   508   509   510   511   512