赞
踩
-- 方法一
Insert into Table2(field1,field2,…) select value1,value2,… from Table1
-- 方法二
Insert into Table2 select * from Table1
-- 方法三
Insert into Table2 select * from Table1 where 条件
Insert into Table2(field1,field2,…) values (select value1,value2,… from Table1)
-- 1、创建测试表 CREATE TABLE Table_1( [name_1] [nchar](10) NULL, [age_1] [int] NULL ) CREATE TABLE Table_2( [name_2] [nchar](10) NULL, [age_2] [int] NULL ) -- 2、添加测试数据 Insert into Table_1 values('Jack',20) Insert into Table_1 values('Lily',25) -- 3、复制表数据部分列和常值 Insert into Table_2(name_2,age_2) select name_1,25 from Table_1 -- 或 Insert into Table_2 select * from Table_1
-- 方式一
SELECT value1, value2 into Table_2 from Table_1;
-- 方拾二
SELECT * into Table_2 from Table_1
-- 方式三
SELECT * into Table_2 from Table_1 where 条件
select name,age into Table_3 from Table_2
如果在Oracle数据库中执行这条语句,会报”ORA-00905:缺失关键字”错误,原因是数据库的区别。
如果想在Oracle中实现该功能,可使用 :
Create table newTable as select * from oldTable;
实例:
-- 1. 复制表结构及其数据:
create table new_table as select * from old_table;
-- 2. 只复制表结构:
create table new_table as select * from old_table where 1=2;
-- 或者:
create table new_table like old_table;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。