1.SQL34 批量插入数据
insert into actor VALUES
(1,'PENELOPE','GUINESS','2006-02-15 12:34:33'),
(2,'NICK','WAHLBERG','2006-02-15 12:34:33')
解题思路:向表中批量插入数据:INSERT INTO table_name VALUES()
- mysql中常用的三种插入数据的语句:
- insert into表示插入数据,数据库会检查主键,如果出现重复会报错;
- replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样;
-
insert ignore表示,如果中已经存在相同的记录,则忽略当前新数据;
- insert ignore into actor values("3","ED","CHASE","2006-02-15 12:34:33");
2.SQL37 对first_name创建唯一索引uniq_idx_firstname
ALTER TABLE actor ADD UNIQUE uniq_idx_firstname (first_name );
ALTER TABLE actor ADD UNIQUE idx_lastname (last_name);
3.SQL38 针对actor表创建视图actor_name_view
CREATE VIEW actor_name_view (first_name_v,last_name_v)
AS
select first_name,last_name from actor
4.SQL39 针对上面的salaries表emp_no字段创建索引idx_emp_no
select *
from salaries
FORCE INDEX (idx_emp_no)
where emp_no=10005
解题思路:强制使用索引:force index(index_name)
5.SQL40 在last_update后面新增加一列名字为create_date
ALTER TABLE actor add create_date datetime not null default "2020-10-01 00:00:00";
6.SQL41 构造一个触发器audit_log
CREATE TRIGGER audit_log
AFTER INSERT ON employees_test
FOR EACH ROW
BEGIN
INSERT INTO audit VALUES(new.id,new.name);
END
解题思路:不会!!!!
7.SQL43 将所有to_date为9999-01-01的全部更新为NULL
UPDATE titles_test
SET to_date = NULL, from_date = '2001-01-01'
WHERE to_date = '9999-01-01';