I this post, I explain how to create your new database on your local computer or on a Web hosting account. After you create a new database, you can add tables to it.
Step 1. Create a new database
In the main panel, the following is displayed
Database Customer has been created
The SQL query that phpMyAdmin sent to create the database, which was:
CREATE DATABASE ‘Customer’
If you’re allowed to create a new database but not allowed to create it in phpMyAdmin, the Web hosting company provides a way for you to create a database from your Web account control panel.
Step 2. Viewing the databases
The SQL query that displays a list of database names is:
SHOW DATABASES
Step 3. Deleting a database
In the phpMyAdmin main page, check the name of the database you want to delete then click “Drop” button.
The SQL query that was executed:
DROP DATABASE Customer
Note: This is an irreversible procedure.
Step 4. Adding tables to a database
Then you need to fill out your columns.
You can also create a table by writing your own SQL query and sending it to the MySQL server. For instance, the query you would use to create the Pet table is
CREATE TABLE Pet ( petID SERIAL, petName VARCHAR (25) NOT NULL, petType VARCHAR (15) NOT NULL, petDescription VARCHAR (255) NOT NULL, price DECIMAL (9,2) NULL, pix VARCHAR (15) DEFAULT “missing.jpg”, ) |
You can also define the first field using the following:
petID BIGINT NOT NULL UNSIGNED AUTO_INCREMENT PRIMARY KEY
After a table has been created, you can query to see it, review its structure, or remove it.
SHOW TABLES
EXPLAIN <tablename>
DROP TABLE <tablename>
Step 5. Changing the database structure
You can change the name of the table; add, drop or rename a column; or change the data type or other attributes of the column. You can change the structure even after the table contains data.
Changing the database structure is very simple. All what you need is click the pencil icon for the field you want to modify.
You can change the table structure with the ALTER query. The basic format for this query is ALTER TABLE table_name, followed by the specified changes.
For example, you can make the petName field wider by sending this query to change the column in a second:
ALTER TABLE Pet MODIFY petName VARCHAR (50)
Have fun!