How to create a data table in MySQL database?
To create a table in a MySQL database, you can use the CREATE TABLE statement. Here is an example:
CREATE TABLE 表名 (
列1 数据类型,
列2 数据类型,
...
);
You need to replace the table name in the code above with the name of the table you want to create, and list the columns of the table and their corresponding data types in parentheses.
For example, if you want to create a table named “users” with columns for id, username, and age, you can use the following code:
CREATE TABLE users (
id INT,
username VARCHAR(50),
age INT
);
In the example above, the data type of the “id” column is INT (integer), the data type of the “username” column is VARCHAR(50) (a string with a maximum length of 50), and the data type of the “age” column is also INT.
After creating the data table, you can use the INSERT statement to add data into the table, for example:
INSERT INTO users (id, username, age) VALUES (1, 'John', 20);
INSERT INTO users (id, username, age) VALUES (2, 'Jane', 25);
This will insert two records into the users table.