做数据库开发的过程中难免会遇到有表数据备份的,而SELECT INTO……和INSERT INTO SELECT…… 这两种语句就是用来进行表数据复制,下面简单的介绍下:

1、INSERT INTO SELECT

语句格式:Insert Into Table2(column1,column2……) Select value1,value2,value3,value4 From Table1 或 Insert Into Table2 Select * From Table1

说明:这种方式的表复制必须要求Table2是事先创建好的

例:

--1.创建表create TABLE Table1(    a varchar(10),    b varchar(10),    c varchar(10)) ;create TABLE Table2(    a varchar(10),    c varchar(10),    d varchar(10));commit;--2.创建测试数据Insert into Table1 values('赵','asds','90');Insert into Table1 values('钱','asds','100');Insert into Table1 values('孙','asds','80');Insert into Table1 values('李','asds',null);commit;--3.复制table1数据到table2中Insert into Table2(a, c, d) select a,b,c from Table1;commit;--或,此种方式必须要求table2和table1的列数相等,而且类型兼容Insert into Table2 select * from table1;commit;

2、SELECT INTO……

这种方式的语句可以在Table2不存在的时候进行表数据复制,编译器会根据Table1的表结构自动创建Table2,Table2和Table1的结构基本上是一致的,但是如果已经存在Table2,则编译器会报错.

这种方式的语句在Oracle中和MS SqlServer中是有点差别的,,如下:

语句格式:

Oracle:Create Table2 as Select column1,column2……From Table1 或 Create Table2 as Select * From Table1

MS SqlServer:Select column1,column2…… into Table2 From Table1 或 Select * into Table2 From Table1

例:

--Oracle--1.创建表create TABLE Table1(    a varchar(10),    b varchar(10),    c varchar(10)) ;commit;--2.创建测试数据Insert into Table1 values('赵','asds','90');Insert into Table1 values('钱','asds','100');Insert into Table1 values('孙','asds','80');Insert into Table1 values('李','asds',null);commit;--3.复制table1数据到table2中Create Table Table2 as select a,b,c From table1;Commit;--或(这两种方式的sql只能应用一次)Create table table2 as select * From Table1;Commit;--删除表drop table table1;drop table table2;commit;

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. vue 基础语法及购物车小案例
  3. python起点网月票榜字体反爬案例
  4. Android(安卓)- Manifest 文件 详解
  5. Android的Handler机制详解3_Looper.looper()不会卡死主线程
  6. Selector、shape详解(一)
  7. android2.2资源文件详解4--menu文件夹下的菜单定义
  8. Android发送短信方法实例详解
  9. Android(安卓)读取资源文件实例详解

随机推荐

  1. Android(安卓)emulated sdcard
  2. Android内存溢出
  3. android 获得listview里的控件的id
  4. Android(安卓)按钮控制ViewPager左右翻页
  5. Android6.0 PackageManagerService(PMS)-
  6. Android Studio 基础 之 如何取消使用 An
  7. Android屏蔽软键盘并且显示光标的实例详
  8. Android(安卓)Day08四大组件之服务Servic
  9. Connection to https://dl-ssl.google.co
  10. android小知识(1)