Home >Database >Mysql Tutorial >使用一条INSERT语句完成多表插入_MySQL

使用一条INSERT语句完成多表插入_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 14:02:302551browse

这是一条颠覆常规的插入方法,一条INSERT语句可以完成向多张表的插入任务。小小地展示一下这种插入方法。

1.创建表T并初始化测试数据,此表作为数据源。


sec@ora10g> create table t (x number(10), y varchar2(10));
sec@ora10g> insert into t values (1,'a');
sec@ora10g> insert into t values (2,'b');
sec@ora10g> insert into t values (3,'c');
sec@ora10g> insert into t values (4,'d');
sec@ora10g> insert into t values (5,'e');
sec@ora10g> insert into t values (6,'f');
sec@ora10g> commit;

2.查看表T的数据


sec@ora10g> select * from t;

X Y
---------- ----------
1 a
2 b
3 c
4 d
5 e
6 f

6 rows selected.

3.创建表T1和T2,作为我们要插入的目标表。


sec@ora10g> create table t1 as select * from t where 0=1;

Table created.

sec@ora10g> create table t2 as select * from t where 0=1;

Table created.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn