How to create a table in MySQL?
To create a table in MySQL, you can use the CREATE TABLE statement. Here’s an example:
To create a table, use the following syntax:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
…
);
Here, table_name is the name of the table you want to create. column1, column2, etc. are the column names in the table, datatype is the data type of the columns, and constraint refers to column constraints such as primary key, unique constraint, foreign key, etc.
For example, to create a table named students with three columns: id (integer type), name (string type), and age (integer type), you can use the following statement:
Create a table for students with columns for ID, name, and age. The ID column is an integer and the primary key, the name column is a variable character with a maximum length of 50 characters and cannot be empty, and the age column is an integer.
This statement will create a table called students, with three columns: id, name, and age. The id column is defined as the primary key, the name column is defined as not null. The age column has no constraints.