Linux中MySQL数据库的使用②-----数据的基本操作

一、插入数据

insert into 表名(字段1,字段2, ...) values(数据1, 数据2, ...);

二、删除数据

delete用来删除数据行,要配合where进行判断。

#将student表中id=2的数据行删除
delete from student where id = 2;

三、修改数据

update语句用来修改数据,一般配合where或者having来进行条件判断。

#将student表中id=1的name字段的数据修改为chenih
update student set name='chenih' where id=1;

四、查看数据

select语句用来查询数据,一般会配合where或者having来进行条件判断。

select * from 表名;
select 字段1, 字段2, ..., 字段n from 表名;
select * from 表名 where 字段名='数据值';
select * from 表名 having 字段名='数据值';

五、复制表格

1.复制表格的数据
原表里的字段的属性不会被复制。

#将新表名中的数据复制到新表名中
create table 新表名 select * from 原表名 ;

2.复制表的结构和属性
不会复制原表中的数据。

create table 新表名 like 原表名 ;

猜你喜欢

转载自blog.csdn.net/weixin_43670190/article/details/108553000