desc 表名;
describe的缩写,意为描述
1 mysql> create table class( 2 -> id int primary key auto_increment, 3 -> name varchar(10) not null default ‘‘, 4 -> gender char(1) not null default ‘‘, 5 -> company varchar(20) not null default ‘‘, 6 -> salary decimal(6,2) not null default 0.00, 7 -> fanbu smallint not null default 0 8 -> );
insert步骤:
mysql> insert into class -> (id,name,gender,company,salary,fanbu) -> values -> (1,‘张三‘,‘男‘,‘百度‘,8888.66,145);
在添加数据之前,如果使用gbk编码,可能导致中文字符的长度不够的错误,所以可以使用:
mysql> set names utf8mb4;
mysql> insert into class -> (name,gender,salary) -> values -> (‘李四‘,‘男‘,9832.23);
这次没有全部添加
虽然没有添加id,但还是显示2,因为前面设置了id为自增的,每次添加数据id都会加一,没有添加的使用默认设置的值。
如果插入所有列,则可以不声明待插入的列,默认为依次插入所有列
此时id也必须添加或写null占位(不推荐,会出现兼容问题),否则不会对应
1 mysql> insert into class 2 -> values 3 -> (3,‘王五‘,‘女‘,‘腾讯‘,3245.23,435);
如果想添加多行,则每行记录间用逗号隔开
1 insert into class (name,company,salary) values (‘刘备‘,‘皇家‘,23.34), (‘曹操‘,‘宦官后裔‘,34.34);
原文:https://www.cnblogs.com/sunbr/p/11715454.html