Home > Database > Mysql Tutorial > Introduction to the method of creating data tables in Mysql (with examples)

Introduction to the method of creating data tables in Mysql (with examples)

不言
Release: 2019-01-08 09:56:09
forward
5368 people have browsed it

This article brings you an introduction to the method of creating a data table in Mysql (with examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The data table is one of the most important components of the database and is the basis for other objects. If our database does not have a data table, it means that there is no real place to store data (recommended course: MySQL Tutorial)

Open the database

We log in After mysql open the database we want to open.

USE keyword

We open the database named test, command:
USE test

After opening the database, we To create a data table, let’s first understand the command rules for creating a data table

CREATE TABLE [IF NOT EXISTS] table_name(
    column_name data_type,
    column_name data_type,
    ...
)
Copy after login

Parameter description

column_name Column name
data_type Data type

Let’s create a basic data Table, username, age, password, salary

CREATE TABLE ta1(
    usename VARCHAR(20),
    age TINYINT UNSIGNED,
    passwrod VARCHAR(16),
    gz FLOAT(8,2) UNSIGNED
)
Copy after login

In the above command, we declare a data table named ta1. The data table has 4 fields.
The usename field is a user name from 1 to 20 characters
age field is a number from 0 to 255, UNSIGINED is expressed as an unsigned type
The passwrod field is a password from 1 to 16 characters
gz field It is 8 digits, with 2 decimal places. UNSIGINED is expressed as an unsigned type

Introduction to the method of creating data tables in Mysql (with examples)

After creating the data table, let’s check whether the creation is successful.

Command rules

SHOW TABLES [FROM ab_name]
[LINK 'pattern' | WHERE expr ]
Copy after login

Enter the command to view the data table:

SHOW TABLES;
Copy after login

Introduction to the method of creating data tables in Mysql (with examples)

After viewing the data table, we Let’s check whether the data structure of the data table is the same as what we created.

Command rules for viewing the data structure:

SHOW COLUMNS FROM table_Name;
Copy after login

Enter the command to view the data structure

SHOW COLUMNS FROM user;
Copy after login

Introduction to the method of creating data tables in Mysql (with examples)

We can see The data structure is exactly the same as what was specified when creating it.

The above is the detailed content of Introduction to the method of creating data tables in Mysql (with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template