MySQL Basic Learning_Lesson 011_MySQL Create Data Table

MySQL create data table

 

1. Syntax format for creating a table

语法格式:

CREATE TABLE 表名 (
字段名1 数据类型 相关约束,
字段名2 数据类型 相关约束,
字段名3 数据类型 相关约束,
...);

Note: The table name of the data table in the database is generally recommended to start with: t_ or tab_

Example: Create a t_testtable data table:

CREATE TABLE t_testtable(
    no bigint,
    name VARCHAR(255) ,
    sex char(1),
    classno VARCHAR(255),
    birth CHAR(10)
);

 

2. The data type of the field

The common ones are as follows:

 

3. How to choose char and varchar

In actual development:

(1) When the length of the data in a certain field does not change, it is fixed-length, for example: gender, birthday, etc. are all of the char type;

(2) When the data length of a field is uncertain, for example: introduction, name, etc., all use varchar type.

Guess you like

Origin blog.csdn.net/weixin_43184774/article/details/115085959