It is very easy to create a table in MySQL.  You need to use the Create table statement to create a table in MySQL. Please check below example

[php]create table table_name(
column1 datatype,
column2 datatype,
column3 datatype

There are three main elements in creating a table:
1. Table name: Name you want to give to your table. You can select any name.
2. column: Column name in your table.
3. datatype: Type of data you are going to store in that column.

But we can add more elements to a table.

let’s do a live example with a brief explanation:

[php]create table students(
student_name varchar(255) NOT NULL,
student_address varchar(255) NOT NULL,
PRIMARY KEY (roll_no)

Let’s explain these above statements:

  • Table name: students
  • columns: roll_no, student_name, student_address
  • datatype: int, varchar
  • Not Null: NOT NULL is used to prevent a user to create a record with a NULL value. If a user will try to create a record with NULL value then MySQL will display an error message.
  • AUTO_INCREMENT: Field Attribute AUTO_INCREMENT tells MySQL to go ahead and add the next available number to the id field.
  • PRIMARY KEY: Keyword PRIMARY KEY is used to define a column as a primary key.

Sharing is caring!

Review Date
Reviewed Item
Author Rating
Rishab Kapoor on FacebookRishab Kapoor on LinkedinRishab Kapoor on TwitterRishab Kapoor on Youtube
Rishab Kapoor
A Blog writer, a Web developer and a passionate teacher. Teaching on YouTube from last 7 years. Like to write articles about Web designing, Web development, Digital Marketing, and Online money making techniques. If you have any question about Web technologies and your career then you can contact me via above my social media profiles.