Search


print PDF

Create, modify and delete a table (of the data base)


How to create a table in the data base?

First of all, we are going to use phpMyAdmin, which is a very easy to use and very efficient.
We are going to create a table in phpMyAdmin: select your database in the left menu


In our example, we are going to use SQL section for the creation of the table called ‘Members’.

Click on ‘SQL’ section, and then enter the following instructions in the text field


Description:
INT: shows that a figure with no decimal must obligatorily be inserted AUTO_INCREMENT: a new ID (a new number) will be automatically inserted in the table. VARCHAR: it is used for limiting the number of characters that we can enter in a field (this is the reason why it is followed by a figure, which corresponds to the maximum number of characters to enter)

We are going to create a ‘members’ table with the following fields: nickname, address, postcode, town and country.

You must get the following message, in the left menu you will find the members table.




How to modify a table in a data base

If you understood how to create a table, you will understand how to modify it as well. It is very easy. See the following example by using our member’s tables again:
Click on ‘SQL’ index then type the following instructions in the field


Description

ALTER TABLE members: Modification of the table named ‘members’
ADD: add the email field in the table

You must get the following message:


We added a field to the ‘members’ table. Now, let’s delete this field from the table.

Click on ‘SQL’ index then type the following instructions in the field


Description

ALTER TABLE members: Modification of the table named ‘members’
DROP: to delete the email field from the table

You must get the following message:


How to delete a table in the database?


After having created and modified our table and its fields, we will now delete it.
Click on ‘SQL’ index then type the following instructions in the field


Description

DROP TABLE members: Deletion of the table named ‘members’
You must get the following message:

Nom de la base: Members
1er champ: CREATE TABLE members (id INT not null AUTO_INCREMENT, nickname VARCHAR (20) not null, address VARCHAR (90) not null , post_code VARCHAR (10) not null , town VARCHAR (90) not null , country VARCHAR (90) not null , PRIMARY KEY (id))