Creating Table in MySQL
Creating Table in MySQL
We can create a table in a database using the CREATE TABLE query in MySQL. Let's create a simple table "Employees", consisting of five columns: "employeeID", "firstname", "lastname", "email" and "joining_date".
The query will look something like this:
Let's break down the attributes:
- NOT NULL - Each row must contain a value for that column, null values are not allowed.
- DEFAULT value - Set a default value that is added when no other value is passed.
- UNSIGNED - Used for number types. It limits the stored data to positive numbers and zero.
- AUTO INCREMENT - MySQL automatically increases the value of the field by 1 each time a new record is added.
- PRIMARY KEY - Used to uniquely identify the rows in a table.
This is how it will look in a PHP script: