Basics mysql learning 02

We look for additions and deletions to change search table of basic syntax:

First, create a simple salary scale:

create table salary(
id int primary key auto_increment,
sname varchar(10) not null default ' ',
gender char(1) not null default ' ',
company varchar(20) not null default ' ',
salary decimal(6,2) not null default 0.00,
fanbu smallint not null default 0
)engine myisam charset utf8;

Then we see the structure of the table: desc table name;

Next we add data to the table:

So where to tables to increase the line? 

insert into 表名

But also where to columns that added value? 

(id,sname,gender,company,salary,fanbu)

The increase in value is the number?    

values

(1, ' John Doe ', ' M ', ' Baidu ', 8888.67,234)

The above code is knocked into a few that we look at the results:

Inserting a plurality of data words, separated by commas as long as the data can be:

  

If we insert the data at the time, if you do not declare a column, the default all columns.

改变表中的数据:update 表名 set  要修改的列=where 表达式;

例如:update salary set fanbu=100 where id=1;

 

 

注意我们在修改数据的时候一定要加上where 表达式,只要where表达式为真,那么该语句就执行,如果不加的话就会把这一列所有的值全部改掉。

删除:指的是删除整行,不存在删除一行中的某几列。

delete from 表名 where 条件;

上面的语句说的就是我们要删除哪张表中的哪几行。

比如我们要删除salary表中fanbu<150的行;

delete from salary where fanbu<150;

 

查询:要思考三个问题,查询哪张表,哪几列,哪几行?

我们来查找一下salary表中的姓名,性别和薪水:

select sname,gender,salary from salary;

上面的只实现了查询哪张表和哪几列,那么哪一行怎么实现呢?

答:添加where 表达式:

select sname,gender,salary from salary where sname='李四';

只要where表达式为真,那么该语句就执行,那么我们也可以换个条件,例如where salary=9534;等等

 

Guess you like

Origin www.cnblogs.com/wanghaoyu666/p/11258052.html