码迷,mamicode.com
首页 > 数据库 > 详细

MySQL表操作

时间:2018-08-26 16:45:53      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:创建   ase   编辑   alter   gnu   null   math   lis   rop   

使用编辑器编辑指令
edit
创建表
create table 表名(
字段1,类型【宽度】约束条件)
==在同一张表中,字段名是不能相同
==宽度和约束条件可选
==字段名和类型是必须的
查看表
show tables;
desc haha;查看表结构
show create table haha;
show table status like ‘haha’ \G
修改表:
alter 修改表名称 ,修改字段名称 修改字段数据类型 修改字段的修饰符
insert 插入数据
delete 删除数据
update 更新数据
修改表名称
rename table haha to xixi;
alter table hh rename xixi;
添加新字段
alter table t1 add math int(10);
alter table t1 add (chinese int(10)),english int(10));
修改字段数据库类型,修饰符 alter只能改数据库类型不能改名
alter table t1 modify chinese int(5) not null;
修改名称,数据类型,修饰符
alter table t1 change chinese china int(6);
first after
alter table t1 change english en int(6) after id;
alter table t1 modify en int(6) first;
删除字段
alter table t1 drop en;
插入数据(添加记录)
字符串必须引号引起来
mysql> insert into t1(id,name,math,china) values(1,"wing",80,90);
mysql> insert into t1(id,name,math,china) values(2,"king",70,100),(3,"tom",50,70);
mysql> insert into t1 values(4,"xiaosan",50,100);
mysql> insert into t1(id,math) values(5,70);
mysql> insert into t1 set id=6,math=65;
更新记录
mysql> update t1 set name="lili" where id=5;
删除记录
mysql> delete from t1 where id=6;
mysql> delete from t1; //删除所有记录
表复制:key不会被复制: 主键、外键和索引
复制一张表
mysql> create table t10(select * from t3);
mysql> create table t10(select id,name from t3);

复制表结构
mysql> create table t4(select * from t3 where 5=4);
mysql> create table t4(select id,name from t3 where 5=4);

复制记录
mysql> insert into t3 select * from t10 where id=9;

删除表
mysql> drop table t1;

删除库
mysql> drop database gnu;

MySQL表操作

标签:创建   ase   编辑   alter   gnu   null   math   lis   rop   

原文地址:http://blog.51cto.com/13939728/2164513

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!