Creating Data Tables in MySQL: A Step-by-Step Guide

Creating Data Tables in MySQL: A Step-by-Step Guide


A Step-by-Step Guide to Importing Excel Data into MySQL


If you followed my previous post, you can easily create a Data Table when importing external data. In this post, I will introduce how to create a Data Table manually.

First, let’s create a database named ‘test_data.’

CREATE DATABASE test_data

Within this database, I’ll create a Data Table. I aim to create a Data Table like the one shown below.

IDRepsVariableYield
11Control116.08
22Control132.85
33Control115.98
41Treatment131.37
52Treatment108.89
63Treatment100.35

Next, let’s create the structure of Data Table.

CREATE TABLE test_data.crop_yield (
    ID INT AUTO_INCREMENT PRIMARY KEY,
    Reps INT,
    Variable VARCHAR(15),
    Yield DECIMAL(5, 2)
);

SELECT * FROM test_data.crop_yield;

Then, I’ll create data.

INSERT INTO test_data.crop_yield (Reps, Variable, Yield) VALUES
    (1, 'Control', 116.08),
    (2, 'Control', 132.85),
    (3, 'Control', 115.98);

INSERT INTO test_data.crop_yield (Reps, Variable, Yield) VALUES
    (1, 'Treatment', 131.37),
    (2, 'Treatment', 108.89),
    (3, 'Treatment', 100.35);
    
SELECT * FROM test_data.crop_yield;


Leave a Reply

If you include a website address in the comment section, I cannot see your comment as it will be automatically deleted and will not be posted. Please refrain from including website addresses.