Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views

Hands-On Lab - Create and Load Tables Using SQL Scripts

Uploaded by

arilane brito
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Hands-On Lab - Create and Load Tables Using SQL Scripts

Uploaded by

arilane brito
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

02/07/2024, 15:38 about:blank

Hands-on Lab: Create and Load Tables using SQL Scripts

Estimated time needed: 20 minutes

In this lab, you will learn how to create tables and load data using the phpMyAdmin graphical user interface (GUI) tool in the MySQL database
service.

Objectives
After completing this lab, you will be able to use phpMyAdmin with MySQL to:

Create a database on MySQL


Create tables using SQL scripts
Load data into tables directly from CSV files

MySQL
In this lab, you will use MySQL. MySQL is a Relational Database Management System (RDBMS) designed to efficiently store, manipulate, and
retrieve data.

To complete this lab, you will use MySQL relational database service available as part of IBM Skills Network Labs (SN Labs) Cloud IDE, the
virtual lab environment used in this course.

Database Used in this Lab


The database used in this lab is internal. You will be working on a sample Cardio-Vascular Diseases (CVD) database. This CVD database schema
consists of five tables: PATIENTS, MEDICAL_HISTORY, MEDICAL_PROCEDURES, MEDICAL_DEPARTMENTS, and
MEDICAL_LOCATIONS.

Each table has a few rows of sample data. The following diagram shows the contents of the CVD database:

about:blank 1/8
02/07/2024, 15:38 about:blank

Your task is to create this database in MySQL. This task is divided into three parts.

Task 1: Create the database on MySQL using the phpMyAdmin GUI.

Task 2: Create all the tables in MySQL using an SQL script.

Task 3: Populate each table with the data in respective CSV files.

Task 1 : Create the database


Follow the instructions shared below to create the database CVD in MySQL.

Launch phpMyAdmin
1. Click Skills Network Toolbox. In the Database section, click MySQL.

To start the MySQL, click Start.

2. Once MySQL has started, click the phpMyAdmin button to open phpMyAdmin in the same window.

about:blank 2/8
02/07/2024, 15:38 about:blank

3. You will see the phpMyAdmin GUI tool.

4. In the tree view, click New to create a new empty database. Then, enter CVD as the name of the database and click Create.

The encoding will be left as utf8mb4_0900_ai_ci. UTF-8 is the most commonly used character encoding for content or data.

about:blank 3/8
02/07/2024, 15:38 about:blank

Task 2 : Create tables using SQL script


In this exercise, you will learn how to execute a script containing the CREATE TABLE commands for all the tables rather than create each table
manually by typing the DDL commands in the SQL editor.

Note: SQL scripts are basically a set of SQL commands compiled in a single file. Each command must be terminated with a semicolon ;. The extension
of the file is to be kept as .sql. Upon importing this file in the phpMyAdmin interface, the commands in the file are run sequentially.

Follow the steps shared below.

Download the script file to your local machine:

CVD_Database_Create_Tables_Script.sql

Select the CVD database. Then click the Import tab.

Click Choose File, browse for the file and upload it.

Once uploaded, scroll down and click Go.

about:blank 4/8
02/07/2024, 15:38 about:blank

The script then gets executed successfully, and the interface shows entries in the image below.

about:blank 5/8
02/07/2024, 15:38 about:blank

Click any of the tables to see its Table Definition (its list of columns, data types, and so on). The image below displays the structure of the
table PATIENTS.

Task 3 : Load data into tables


You now need to load the data to the tables. You could manually insert each row into the table one by one, but that is highly inefficient. Instead,
MySQL (and almost every other database) lets you load data from CSV files directly to the tables.

The steps below explain loading data into the tables you created in Task 2.

1. Download the 5 CSV files below to your local machine.

Patients.csv
about:blank 6/8
02/07/2024, 15:38 about:blank
MedicalHistory.csv
MedicalProcedures.csv
MedicalDepartments.csv
MedicalLocations.csv

The steps to load a CSV to a table are as follows.

Select the table.

Click the Import tab.

Browse to the location of the CSV file and click ‘Go’ to load the CSV file.

The images below share how to load the CSV data to the PATIENTS table.

Once the table is loaded, you will get a message that the records are inserted successfully.

Further, you can click on browse and view the table's data.

Practice exercise
Repeat the same process for all of the other tables.

Conclusion
Congratulations on completing this lab.

In this lab, you learned how to :

about:blank 7/8
02/07/2024, 15:38 about:blank
Use phpMyAdmin GUI to operate on MySQL servers

Create a new database in phpMyAdmin.

Create the tables for the dataset using SQL scripts

Load data from a CSV file directly to a table in MySQL.

Author(s)
Dmytro Yesyp

Additional Contributor(s)
Abhishek Gagneja

Changelog
Date Version Changed by Change Description
2023-10-09 1.3 Steve Hord QA pass with edits
2023-10-06 1.2 Misty Taylor ID Check
2023-09-09 1.1 Abhishek Gagneja Modified the instructions
2023-08-02 1.0 Dmytro Yesyp Initial version created

© IBM Corporation 2023. All rights reserved.

about:blank 8/8

You might also like