手机
当前位置:查字典教程网 >编程开发 >数据库其他 >数据库插入数据之select into from与insert into select区别详解
数据库插入数据之select into from与insert into select区别详解
摘要:可能第一次接触select...into...from...和insertinto...select...有很多人都会误解,从表面上看都是把...

可能第一次接触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区别详解1

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

数据库插入数据之select into from与insert into select区别详解2

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

数据库插入数据之select into from与insert into select区别详解3

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

数据库插入数据之select into from与insert into select区别详解4

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

数据库插入数据之select into from与insert into select区别详解5

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

数据库插入数据之select into from与insert into select区别详解6

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

数据库插入数据之select into from与insert into select区别详解7

END

注意事项

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

【数据库插入数据之select into from与insert into select区别详解】相关文章:

数据库正规化和设计技巧

数据库命名规范小结

sql left join 命令详解

数据库中的左连接(left join)和右连接(right join)区别

MSSQL内连接inner join查询方法

SQL之left join、right join、inner join的区别浅析

复杂系统中的用户权限数据库设计解决方案

Access数据库升级为SQL数据库的注意事项和方法

JDBC 数据库常用连接 链接字符串

update 子查询使用介绍

精品推荐
分类导航