sql 语句系列(插入系列)[八百章之第四章]

复制数据到另一个表

这个不解释,只是自我整理。mysql

insert EMP_EAST (DEPTNO,DNAME,LOC)
select DEPTNO,DNAME,LOC
from DEPT
where LOC in ('NEW YORK','BOSTON')

复制表的定义

说白了就是复制表的结构,pass 平台用的挺多的,须要动态建立表。sql

select * into dept_2
from DEPT
where 1=0

介绍一下mysql的:code

create table dept_2
as
select *
from dept
where 1=0

禁止插入特定的列

好比说有一张表,你只容许它插入某些固定的行,其余行不让插入。table

不少人会以为这个需求很奇怪,不让插入那么要其余列干啥呢?其余列可能就是默认值了。class

实现这种需求也特别简单,采用视图的方式,原理就是更新视图那么对应的表也会更新。原理

create view new_emps as
select empno,ename,job
from EMP

而后插入视图,就能够了。select

insert into new_emps(empno,ename,job)
values(1,'xxx','xxx')