Create a table in mysql database

Create a table in mysql database

If we want to create a table in mysql database, require name of the table, list of fields with definition.

MySql Create Table Generic Syntax

CREATE TABLE  (
column_name1 column_type1,
column_name2 column_type2,
.............
..........
);

Let us create a employee table in new database mysqldemo,

Create a new database 'mysqldemo',

mysql> create database mysqldemo;

Output:

Query OK, 1 row affected (0.03 sec)

Using the new database,

mysql> use mysqldemo;

Output:

Database changed

We are going to create a table 'tblemployee' with fields empid, emp_name, dept_id and salary.

mysql> create table tblemployee(
    ->    emp_id INT NOT NULL AUTO_INCREMENT,
    ->    emp_name VARCHAR(100) NOT NULL,
    ->    dept_id INT,
    ->    salary INT,
    ->    PRIMARY KEY ( emp_id )
    -> );

Output:

Query OK, 0 rows affected (0.10 sec)

Lets check whether table is created or not using show tables

mysql> show tables;
+---------------------+
| Tables_in_mysqldemo |
+---------------------+
| tblemployee         |
+---------------------+
1 row in set (0.01 sec)



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^