找回密码
 立即注册
mysql 表数据结构的操作方法:alter table 操作表结构
修改表名称: rename 更改数据库名称
alter table 原表名 rename 更改的名称
修改字段名称:
change:
alter table wuhan change id s_id int(4);
change 除了可以修改 字段名称
也可修改表里的属性内容
删除自增长,修改也会自删除自增长
alter table wuhan change s_id s_id int(4);
id 被修改的字段
                                                         s_id 修改的新的名称
change 除了可以修改 字段名称
        也可以修改表里面的属性内容.

        也可以进行删除自增长

        给字段增加自增长约束;
        alter table wuhan change s_di s_id int(4)auto_increment;

        删除自增长,修改也会删除自增长
        alter table wuhan change s_id s_id int(4);


change 也可以修改数据类型
已存在数据的改不了
add:他是用来添加字段
alter table wuhan23 add age int(4);
alter table wuhan23 add (age int(4),agel int(4);
add 添加值的同时也可以给约束
alter table wuhan23 add sex char (4) not null;

add 也可以 结合 first 和 after使用:
        添加新的字段时进行调整位置
        alter table wuhan add dcs17 char(4)first;









modify 调整已经存在字段的顺序:

                first: 将字段挪到第一个
                after: 将字段挪到指定字段的后方.
drop 删除:
删除表字段:
alter table wuhan24 drop dcs17;
删除多个字段
alter table wuhan24 drool dcs17 dcs18;

删除主键约束 想要删除主键必须删除自增长:
alter table wuhan24 drop primary key;
增加主键 增加自增长
alter table wuhan24 change id id int(4)primeary
key auto_increment;
alter table 针对表的结构进行操作;
create drop alter table 都是属于表结构操作方法

表数据操作语法:
insert   into   select  update delete
插入                  查询  修改      删除

select:查询的方法
select *from 表名:查询所有的表数据
*:匹配所有内容
1.查询指定 字段的信息内容
select phone from wuhan24;
select phone,class from wuhan24;
2.select 语句条件查询 需要用到where 条件语句
=条件;
select * from wuhan24 where phone=12232332432432;
!= 条件:
         select * from wuhan where name != "niuyi";

        > 大于:
         select * from wuhan where time > "2022-07-01";

        < 小于:
         select * from wuhan where time < "2022-07-01";

        >= 大于等于

        <= 小于等于












select * from wuhan where time > "2022-07-01";
select * from wuhan where time < "2022-07-01";
逻辑运算符号
and 且的关系
select  * from wuhan24 where id=4 and phone =123343241;


or 与的关系
select  * from wuhan24 where id=4 or phone =1234455534;
查询 null
is null;
not is null;
null 是一个属性,"" 他是没有任何数据

in
not in









between: 查询区间范围的值
select * from wuhan11 where time between
“2002-07-01”and“2022-07-03”;

limit:用来查询指定行数的值
select * from wuhan11 limit 2,3;


like:
select * from wuhan11 where name like "%san";
匹配内容。
%在哪里就控制匹配的方向:左右
order by 排序
升序 asc ;  由小到大排序
降序 desc; 由大到小排序
U$VJ@5FWL}3`PGV]`250{40.jpg


聚合函数:
max 最大  min 最小  avg 平均值 sum求和
count 统计 distinct 去重 去除重复的数据 用的非常多


P2UK5D_QTH7$TL_VYPJ]%$F.jpg
JSA55LA$$BSB`N`7}XYGPQ9.jpg
J1_T0Z4JG64X9L2@@%{@U7H.jpg
APO97Y[Z9P9%G7R(I185WSV.jpg
]I(LSEHN92A%L$I)(10V7E8.jpg
@Q[FEMV899E([CB9DG3M.jpg







分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册