In this tutorial, We will learn how to create a database and table of MySQL.



Create database:

Create testdb database using following query.


CREATE DATABASE testdb; 


Create table:

here I am creating a post table with auto increment ID and primary key.

create table post(
   id INT NOT NULL AUTO_INCREMENT,
   title VARCHAR(100) NOT NULL,
   auther VARCHAR(40) NOT NULL,
   post_date DATE,
   PRIMARY KEY ( id)
);


 DESC post;

it will return the description of post table;

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| title     | varchar(100) | NO   |     | NULL    |                |
| auther    | varchar(100) | YES  |     | NULL    |                |
| post_date | date         | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+




an example will create a database in a table I hope this will help you for creating a database and table of MySQL



Are you facing problems in understanding this article?
You can watch the video. Watch it now