Creating a database is not enough to use it. To be able to insert any data we must first create tables, with colums and rows to organise our data.
We will start creating a very simple table called users. Our table will have three columns: id (the primary key), name and surname.
We can create our table with a GUI like phpMyAdmin, or run a SQL command manually:
1 2 3 4 5 |
CREATE TABLE `examples`.`users` ( `id` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 50 ) NOT NULL , `surname` VARCHAR( 50 ) NOT NULL ); |
When you create a table you have to list its columns, and for each of them you should provide:
- column name: (mandatory)
- datatype (mandatory) e.g. INT, VARCHAR, FLOAT, TEXT etc
- length in parenthesis
- attributes e.g. UNSIGNED
- NULL / NOT NULL
- extra e.g. AUTO-INCREMENT
- set if it’s a primary/foreign key