How to create a table in MySQL?

To create a table in MySQL, you can utilize the CREATE TABLE statement.

Here is an example demonstrating how to create a table named users that includes columns for id, name, and email.

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(50),
  email VARCHAR(100)
);

In the example above, ‘users’ is the name of the table, ‘id’ is an auto-incremented integer column, set as the primary key. ‘Name’ and ’email’ columns are character type columns that can store strings with maximum lengths of 50 and 100 characters respectively.

You can adjust the data type and length of the column according to specific needs.

After executing the above CREATE TABLE statement, a new table named users will be created.

bannerAds