美文网首页
MySQL中创建table的流程

MySQL中创建table的流程

作者: 田小田txt | 来源:发表于2018-08-13 15:54 被阅读0次

创建表;

create table stu(id int(5)auto_increment not null primary key comment'主键',name char(3) not null comment'姓名',
age int(2) not null comment '年龄')comment'学生姓名表';

查看创建表用的动作;

show create table stu;

向表内插入数据;

insert into stu(id,name,age) values(1001,'小明',18);

查看表的结构;查看表内的数据;

desc stu; select * from stu;

增加列;

alter table stu add phone char(11) not null fist(或after 字段名称);

删除列;

alter table stu drop phone;
delete from stu where id = '';

清除表内数据;

delete stu;/truncate stu;

更改字段的属性及设置;

alter table stu modify phone null;

设置及删除字段的默认值:
alter table stu alter phone set default = '18834561234';
alter table stu alter phone drop default;

挑选出符合条件的数据;

select id,name from stu where id = 1001;
select id from stu where name like '%明';

更新与更改行中的数据;

update stu set age = '19' where id = 1001;

相关文章

网友评论

      本文标题:MySQL中创建table的流程

      本文链接:https://www.haomeiwen.com/subject/zejubftx.html