MySQL学习笔记

1.创建一个和test差不多的表demo;

create table demo like test;

insert into demo select * from test;

2.修改表的内容:

Update test set name=jerry;【将全部的name都改成jerry】

Update test set name=jerry where id=2;【将第二的name改成jerry】

3.在test表里加一个age列,该列的数值不为空切,默认值为20;

Alter table test

Add age int(3) not null default 20;

 

 4.修改命令:   

1)update test set age =22 where id=5 or id=7;//同一列不能使用and,因为不可能出现ID即等于5又等于7的情况;【多个条件下修改同一个值】

 

2)一个条件下修改多个值;

 update test

    -> set name='tom',

    -> age=23

-> where id=6;

 

3)修改多个表的数值

update test,demo

    -> set test.name='qin',demo.name='qin'

-> where test.id=8 and test.id=demo.id;  自然连接

替换表中的值:

replace into test(id,name,age) values(1,'王五',24);

4.删除表格【可恢复】

     delet from test Where id=10;

删除表格【不可恢复】

     delet from 表名 where条件;

E.g:Delete from student where name=‘王美丽’;

5.索引:

1、1)普通索引

2)唯一索引

3)主键【主索引】

4)全文索引

2、创建一个索引:

①表已经存在:

【create index语句并不能创建主键】

create index idx_name on test(name);【idx_name是索引】创建一个普通索引(属性值可以重复)

②表中为创建索引:创建索引;

③查看表中索引:show index from test;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值