【SQL】使用一条INSERT语句完成多表插入
这是一条颠覆常规的插入方法,一条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.
4.第一种多表插入方法INSERT ALL
1)完成INSERT ALL插入
sec@ora10g> insert all into t1 into t2 select * from t;
12 rows created.
这里之所以显示插入了12条数据,实际上表示在T1表中插入了6条,T2表插入了6条,一共是12条数据。
2)验证T1表中被插入的数据。
sec@ora10g> select * from t1;
X Y
---------- ----------
1 a
2 b
3 c
4 d
5 e
6 f
6 rows selected.
3)验证T2表中被插入的数据。
sec@ora10g> select * from t2;
X Y
-
相关文档:
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREATE DATABASE da ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default \'默认值\' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [ ......
【转】一些常用的sql语句字符串处理,转于这里,以方便使用
一、字符转换函数
1、ASCII()
返回字符表达式最左端字符的ASCII 码值。在ASCII()函数中,纯数字的字符串可不用‘’括起来,但含其它字符的字符串必须用‘’括起来使用,否则会出错。
2、CHAR()
将ASCII 码转换为字符。如果没有输入0 ~ ......
①。启动Distributed Transaction Coordinator 服务
打开服务,在服务中找到Distributed Transaction Coordinator服务,选择“属性”;
在“登录”选项卡中,选择“此帐户”,帐户名填写“N ......