当前位置:Gxlcms > 数据库问题 > 一份数据库笔试题

一份数据库笔试题

时间:2021-07-01 10:21:17 帮助过:2人阅读

update b,a set b.Name=a.Name where a.ID=b.ID;

2.当b表不存在a表ID的记录时,将a表的记录插入到b表中

insert into b select * from a where a.ID not in(select id from B);

3.去掉表a中重复的Name的记录。

delete from a where a.name in (select b.name from(select d.name from a d group by d.name having count(d.name)>1)b) and a.id not in (select id from (select max(c.id) id from a c group by c.name having count(c.name)>1)f);

这里select d.name from a d group by d.name having count(d.name)>1改成(select b.name from(select d.name from a d group by d.name having count(d.name)>1)b) 的原因是Mysql数据库,如果不改成这样会出现错误:

1093 - You can‘t specify target table ‘a‘ for update in FROM clause。

文档“Currently, you cannot update a table and select from the same table in a subquery.”

数据库这样子设计性能会降低吧?

4.设置表a的ID字段为主键

alter table a add primary key(ID);

 删除主键alter table a drop primary key(ID);

5.在表a添加ReMark描述字段

alter table a add ReMark char(50);

6.

一份数据库笔试题

标签:

人气教程排行