Mysql不常用的sql
/////////////////////////////

create table actor(
actor_id smallint(5) primary key not null,
first_name varchar(45) not null ,
last_name varchar(45) not null ,
last_update date not null
)
//1.创建一张表

insert ignore into actor(actor_id,first_name,last_name,last_update)
values('3','ED','CHASE','2006-02-15 12:34:33')
//2.插入新数据,如果源数据有重复则忽略

create table actor_name(
first_name varchar(45) not null,
last_name varchar(45) not null
);
INSERT into actor_name
select first_name,last_name from actor;
//3.创建一张新表,从原表中选取相关数据插入到新表

ALTER TABLE actor ADD UNIQUE uniq_idx_firstname (first_name),add INDEX idx_lastname (last_name)
//4.为一张表添加索引

create VIEW actor_name_view
as
SELECT first_name as first_name_v,last_name as last_name_v
from actor
LIMIT 2;
//5.从新表中选取两列(重新命名),并为之创建视图

SELECT *
from salaries
force index (idx_emp_no)
where emp_no = 10005
//6.使用强制索引

Alter table actor add COLUMN create_date datetime not null DEFAULT '2020-10-01 00:00:00'
//7.对表新增一字段并赋给默认值

create TRIGGER auditt_log
AFTER insert on employees_test
for each ROW
BEGIN
insert into audit VALUES(new.id,new.name);
END
//8.构造一个触发器(在进行某个操作之后,会触发新操作)

Alter table audit ADD
CONSTRAINT FOREIGN key (emp_no)
REFERENCES employees_test(id)
//9.为一个表的某字段创建一个外键,(与别表的某个字段形成关联)