# alter table m1 add birth date not null default '0000-00-00'; Alter table table_name add column_name column_type column_param; [add column end of table]
# alter table m1 add gender char(1) not null default '' after username; Alter table table_name add column_name column_type column_param after column_x [add column after column_x]
# alter table m1 add pid int not null default 0 first; Alter table table_name add column_name column_type column_param first [add first column]
del column
1
Alter table table_name drop column
update column_type
1 2
# alter table m1 modify gender char(4) not null default ''; Alter table table_name modify column_name column_type column_param
update column_type and column_name
1 2 3
# alter table user change name names varchar(30) not null default '';
alter table table_name change old_column_name new_column_name column_type column_params
5 Types of Select
1. where
1
Select * from tableName where id >=2;
SQL
Description
like
just like
%
all words
‘_’
single word
where expr is true the result of select can looks like table.
1 2 3
select count(*) form user; select count(1) from user; [good] select uid,sum(age) from user; [wrong]
having
limit function like avg/sum atc.
1 2 3 4 5
# select name ,sum(score) from student group by username having sum(score)>300 ; show sum of score bigger than 300 and group by name
# select productid,cateid,avg(price),sum(price) from shop_product group by cateid having productid < 1000; show productid , avg(price),sum(price) from shop_product group by cateid having productid<1000.
instead of where is wrong.
Order by
1 2 3
# select username from qtjk_user where userid<20 order by logintime desc,userid asc limit 0,3;