How do you write the statement to create a table in MySQL?

In MySQL, tables are created using the CREATE TABLE statement. Here is an example of the syntax for the CREATE TABLE statement:

CREATE TABLE table_name (
    column1 datatype constraint,
    column2 datatype constraint,
    ...
);

In this case, table_name is the name of the table to be created, column1, column2, etc. are the names of the columns in the table, datatype is the data type of the columns, and constraint refers to the constraints on the columns (such as primary key constraints, foreign key constraints, etc.).

Below is an example of a CREATE TABLE statement that creates a table named students with three columns: id, name, and age.

CREATE TABLE students (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT
);

In the above example, the id column is defined as type INT and set as the primary key constraint; the name column is defined as type VARCHAR(50); the age column is defined as type INT.

bannerAds