#增删改查
#增
1.
insert into ban
(name,age,email,tel,riq)
values
('刘备',99,'liubei@shu.com','15939056812','2012-12-26');
由于没有匹配好相应的属性,所以出现了错误,(当然上面是更正后的),
仔细观察可以发现,多指定一个salary属性,这是因为赋值数目与指定的或隐含的列数或变量数不一样。所以才会报错。
2.
//主键不能重复
insert into ban
values
(1,'关羽',89,'guanyu@wei.com','454564',1234.56,'2011-01-01');
正确的是:
insert into ban
values
(2,'关羽',89,'guanyu@wei.com','454564',1234.56,'2011-01-01');
3.
//一下插入多个行
insert into ban
(name,age,tel)
values
('张飞',12,'110'),
('赵云',69,'220'),
('李白',108,'233'),
('杜甫',15,'456');
delete from ban where id=999;
//注意,在执行一条语句的时候,明明执行成功了,但是为什么数据库没有修改呢?
//这是因为id传错了,找不到正确的id,所以修改不了
#改
修改前:
修改后:
update ban
set
email='machao@xiliang.com',
salary='3999.34'
where id=6;
![](https://i-blog.csdnimg.cn/blog_migrate/1adb3d101571c69e9f692f2e0216ae30.png)
#删
//不存在单独删除哪几列
delete from ban where 1>2;//错误
delete from ban where id=6;
delete from ban where name='刘备';
select *from ban;
![](https://i-blog.csdnimg.cn/blog_migrate/2f9f2c07ce1480ec18c33741f3e4d9d2.png)