Home  >  Article  >  Database  >  MySQL基本数据操作_MySQL

MySQL基本数据操作_MySQL

WBOY
WBOYOriginal
2016-06-01 12:59:56941browse

创造数据(插入数据)

<code class=" hljs sql">insert into 表名(字段列表) valuse(值列表);

insert into exam_student(stu_name,stu_no) values('xiaoming','1205040219');

\

如果需要在插入数据时,为所有的字段设置值,那么可以省略字段列表,要求与表中的字段顺序一致。

insert into exam_student values('zhangsan','3203423',100);

获得数据(查询数据)

<code class=" hljs sql">select 字段列表 from 表名 查询条件;

字段列表可以使用*代替,表示所有的字段。查询条件可以省略,表示所有的记录都获得,相当于where 1;

select stu_name,stu_no from exam_student;

\

<code class=" hljs sql">alter table exam_student add stu_score int;
select * from exam_student;

有条件的查找:

<code class=" hljs sql">select * from exam_student where stu_age>50;

\

删除数据

<code class=" hljs sql">delete from 表名 条件;
删除需要在逻辑上严格给条件,否则容易造成数据误操作,导致损失。
语法上可以没有where。
delete from exam_student where stu_age>50;

\

修改数据

<code class=" hljs sql">update 表名 set 字段=新值,··· 条件;

update exam_student set stu_age=88 where stu_age<=50;

\

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn