~欢迎进来我的博客~蛋叔的小乖乖~

mysql基础命令回顾

1.创建表:
CREAT TABLE student(
id int(2),
name varche(8),
course varchar(20),
score int(20),
)
2.向表中添加内容:
INSERT INTO student(id,name,course,score)VALUES('01','张三','数学','67');
INSERT INTO student(id,name,course,score)VALUES('02','王五',语文','87');
3.修改表
修改表名
ALTER  TABLE  student RENAME AS/TO student_one;
修改列名
alter table student change kecheng course VARCHAR(6);
修改列的数据类型
alter table student MODIFY COLUMN sname varchar(40);
为字段设置默认值
alter table student alter course set default '数学'
为字段删除默认值
alter table student alter course drop default
增加列,多列
alter table student add class varchar(40) comment '班级';
alter table student add ranking int(100) comment '排名';
备注:rank不能作为列明,rank()为排名的函数;int最长字符长度255,不能超长,超长会报错1439
删除列
alter table student drop id
查看索引
show index from student
添加索引
alter table student add index index_id(id)
添加唯一限制条件索引
alter table student add unique index_id(id);
删除索引
alter table student drop  index_id;
联合唯一索引
alter table tablename add unique index index-name (col-1-name, col-2-name);
删除表
drop 表名
返回码:
1064:语法错误
1060:重复字段
1061:重复索引
1062:复制索引
1091:检查是否存在
1439:超出字符长度限制,最长255
 
 
posted @ 2020-02-23 22:20  qq的天马行空  阅读(71)  评论(0)    收藏  举报
蛋叔的小乖乖