SQL233 针对上面的salaries表emp no字段创建索引idx emp no
select *
from salaries
force index (idx_emp_no)
where emp_no=10005
SQL234 在last update后面新增加一列名字为create date
ALTER TABLE actor
ADD (create_date datetime NOT NULL DEFAULT '2020-10-01 00:00:00');
SQL235 构造一个触发器audit log
create trigger audit_log
after insert on employees_test
for each row
begin
insert into audit values(new.id,new.name);
end
SQL236 删除emp no重复的记录,只保留最小的id对应的记录
DELETE FROM titles_test
WHERE id NOT IN(
SELECT * FROM(
SELECT MIN(id)
FROM titles_test
GROUP BY emp_no)a); -- 把得出的表重命名那就不是原表了
SQL237 将所有to date为9999-01-01的全部更新为NULL
update titles_test set to_date = null , from_date = '2001-01-01'
where to_date = '9999-01-01'
SQL238 将id=5以及emp no=10001的行数据替换成id=5以及emp no=10005
REPLACE INTO titles_test
VALUES(5, 10005 ,'Senior Engineer', '1986-06-26', '9999-01-01') ;
SQL239 将titles test表名修改为titles 2017
alter table titles_test rename titles_2017
SQL240 在audit表上创建外键约束,其emp no对应emplovees test表的主键id
ALTER TABLE audit
ADD CONSTRAINT FOREIGN KEY (emp_no)
REFERENCES employees_test(id);
SQL242 将所有获取奖金的员工当前的薪水增加10%
update salaries
set salary=salary*1.1
where to_date='9999-01-01'
and salaries.emp_no in(select emp_no from emp_bonus)
SQL244 将employees表中的所有员工的last name和first name通过引号连接起来
select concat(last_name, '''', first_name) as name
from employees;