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.
ID | Reps | Variable | Yield |
1 | 1 | Control | 116.08 |
2 | 2 | Control | 132.85 |
3 | 3 | Control | 115.98 |
4 | 1 | Treatment | 131.37 |
5 | 2 | Treatment | 108.89 |
6 | 3 | Treatment | 100.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;
© 2022 – 2023 https://agronomy4future.com