MySQL Create database


The CREATE DATABASE syntax is used to create a database.

CREATE DATABASE db_name

Note

Creating a database requires corresponding user rights, such as the root user


Select the database

To perform operations on a database or table, you need to select a database.

use db_name;

Create a table

Grammer

CREATE TABLE table_name
(
   Column1 data_type,
   Column2 data_type,
   Column3 data_type
)

In the above syntax, column(1,2,3) is the field name, followed by the data type.

Example :

CREATE TABLE user
   id mediumint(8),
   username varchar(20),
   password char(32),
   email varchar(40)
);

Principle

In general, the creation of data tables have the following precautions

  • The original record data and the corresponding relationship between the table
  • Table names and field names should follow the naming syntax and should be explicitly defined
  • Specifies the data type of the field
  • Specifies whether the field's other attributes are non-null, whether there are default values, and so on
  • Definition of the properties of the table such as the main foreign keys, constraints, indexes and so on
  • Relationship with other tables
Limited to space and ease of control for the tutorial, do not start too much in this discussion.


Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook