select into from 数据库插入数据之select into from与insert into select区别介绍

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

select into from 数据库插入数据之select into from与insert into select区别介绍

  2021-03-19 我要评论
想了解数据库插入数据之select into from与insert into select区别介绍的相关内容吗,在本文为您仔细讲解select into from的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:select,into,from,insert,下面大家一起来学习吧。

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

步骤/方法

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

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

select into from与insert into select区别详解 

END

注意事项

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们