当前位置:趣知科普网>游戏数码>电脑>

select into from与insert into select区别详解

电脑 阅读(1.45W)

可能第一次接触...和insert ct...有很多人都会误解, 从表面上看都是把相关信息查询出来,然后添加到一个表里,其实还远远没有这么简单,接下来,小猪就用最普通的表述给大家介绍一下这两者间的区别。

步骤/方法

(01)首先,我们来看一下insert into select语句,其语法形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1。

select into from与insert into select区别详解

(02)这里的要求就是Table2必须已经存在,如果不存在,系统则会提示对象无效。

select into from与insert into select区别详解 第2张

(03)同时因为Table2已经存在,所以我们就可以任意的向Table2中加入符合列类型的内容,当然也包括常量,也许通过下面的图,你就会发现,在导入常量时候的不寻常现象了。

select into from与insert into select区别详解 第3张

(04)接下来说一下select into from 语句,该语法形式为:SELECT vale1, value2 into Table2 from Table1。

select into from与insert into select区别详解 第4张

(05)这里要求的是MyTable1不存在,因为在插入的时候,系统会自动创建MyTable1,如果之前MyTable1已经被创建,系统就会提示已经存在表。

select into from与insert into select区别详解 第5张

(06)就是因为这个特性,就会给我们带来很多的方便,首先,我如果只想要MyTable2表中的ID列的话那我只需要将ID列select出来,然后加入到新表中即可。

select into from与insert into select区别详解 第6张

(07)那如果我想要MyTable2中的Name列,那我也仅仅是需要把Name列select出来,然后添加到新表中即可。

select into from与insert into select区别详解 第7张

特别提示

应用范围由实践者自己找到答案~