How do you write code to create a data table in MySQL?
The code for creating a data table in MySQL is written as follows:
CREATE TABLE table_name (
column1 datatype constraints,
column2 datatype constraints,
...
);
The table_name represents the name of the data table to be created, with column1, column2, etc. being the column names within the table, datatype representing the data type of the columns, and constraints representing the constraints on the columns.
For example, creating a data table called users with four columns: id, name, age, and email. The id column is of integer type, while the name and email columns are of string type, and the age column is of integer type. You can use the following code:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
age INT,
email VARCHAR(100)
);
In the above code, the id column is defined as the primary key, and the name column is defined as non-null.