MySQL Database and Tables
This tutorial demonstrates how to SQL statement that creates MySQL database tables in which to store data.
A simple database table look like this :
Creating a database :
1 |
CREATE DATABASE YOUR_DATABASE_NAME; |
In MySQL you can display a list of all databases by using this query :
1 |
SHOW DATABASES; |
Use an existing database using this query :
1 |
USE DATABASE_NAME; |
- The SHOW TABLES; query used to display a list of all tables in a database, if this query return a “empty set” message there are no table in the database.
Creating tables :
A MySQL table is created by this query :
1 |
CREATE TABLE IF NOT EXISTS table_name(col type, col type) |
e.g :
1 2 3 4 5 |
CREATE TABLE IF NOT EXISTS student ( id int(8) NOT NULL, name varchar(8) NOT NULL, rollno int(10) NOT NULL ); |
You can discover the format of any table by using these two queries :
1 2 |
EXPLAIN table_name; DESCRIBE table_name; |
Both query will return same result.
A table may also be deleted from a database with this query :
1 |
DROP TABLE table_name; |