复制数据库中的表格 新建一个新的表 所有属性。再添加属性

来源:互联网 发布:免费财务记账软件 编辑:程序博客网 时间:2024/05/22 11:44
新表select * into newtable from oldtable  insert into newtable select * from oldtable  ---表结构致insert into newtable搜索(列名1,列名2,.....) select 列名1,列名2....from oldtable --表结构

 

1、既复制表结构也复制表内容SQL语句:CREATE TABLE tab_new AS SELECT * FROM tab_old;2、只复制表结构复制表内容SQL语句:CREATE TABLE tab_new AS SELECT * FROM tab_old WHERE 1=2;3、复制表结构只复制内容sql语句:insert into tab_new select * from tab_old;或者SELECT vale1, value2 into Table2 from Table1

 

 

create table 新表名 as select t.*, sysdate 新加字段 from 旧表 t;

 

--------------------判断表是否存在,进行删除表的操作。----------------------------------

CREATE OR REPLACE PROCEDURE CREATE_TABLE(tablename in varchar2) AStablecount int := 0;
BEGIN
select count(1) into tablecount from all_tables where TABLE_NAME = tablename AND OWNER = 'ZXIN'; if (tablecount = 0) then
begin
drop table tablename;
end;
end if;
end;

---------------判断表B是否存在,进行删除B表。然后复制A----新建B

CREATE OR REPLACE PROCEDURE CREATE_TABLE(tablename in varchar2) AStablecount int := 0;
BEGIN
select count(1) into tablecount from all_tables where TABLE_NAME = tablename AND OWNER = 'ZXIN';

if exists (select * from sysobjects where name='OM_ORDER_HIS') then
begin
drop table OM_ORDER_HIS;
end;
end if;

create table OM_ORDER_HIS as select t.*, sysdate HIS_DATE from om_order t;

end;

 

 

 

 

0 0
原创粉丝点击