mysql4

1.插入

如果是将所有的字段都插入,那么就直接使用,如果没有具体的数值也可以用null进行代替。

insert into teacher values(8,"啦啦","嗯嗯",8)

 

对于有限的字段就使用

insert into teacher (name,address,sid) values("啦啦2","来了",9)

 

对于insert和update和delete语句,可以使用low_priority,这样降低优先级,减少性能损耗、

insert low_priority into teacher (name) values("美妞1")

 

多条数据插入,中间用逗号隔开。

insert into teacher (name,address,sid) values("啦啦2","来了",9),("啦啦3","来了1",10)

 

2.修改

update teacher set name ="美妞0" where tid =9

 

3.删除,只能删除行,不能删除表本身。

delete from teacher where tid=12

 

如果想删除表中的所有的行,那么就使用 truncate 本身就是截断的意思。其实就是删除整个表然后又重新创建了新表。

truncate table teacher

 

4.创建表,可以在表名的前面添加if not exists这样进行判断,如果表不存在,那么就创建表。

虽然是设置not null 但是仍然能够插入成功,默认应该是空串。但是应该设置默认的插入值。

create table if not exists teacher

(tid int primary key auto_increment,

name varchar(20) not null default "",

sex varchar(20) not null,

sid int

)

 

5.可以进行制定引擎,一般有三种引擎

innodb  事务处理引擎,但不支持全文本搜索

memory 存储在内存中,速度很快,适合临时表。

myisam 支持全文本搜索,但不支持事务。

 

指定默认引擎

create table teacher (tid.....)engine = innodb

 

6.修改

添加列

alter table teacher add test varchar(20)

删除列

alter table teacher drop test

 

使用alter table定义外键,这里的ee就是约束名,可以自己取名,这时候在teacher表中必须已经存在sid字段,下面的仅仅是添加外键约束。

alter table teacher add constraint ee foreign key(sid) references student(sid)

 

7.删除表

drop table teacher

 

8.重命名表

rename table teacher to teacher1

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值