創建一張表和已有表結構一樣

再做一些數據遷移時候,很多人會使用create table as select * from table where id=-1的方式來年建立一摸一樣的表,但是這樣做有個很大的弊端,不能將原表中的default value也一同遷移過來,可以看下面的例子:

 

第一,新建一個表 

 

-- Create table
create table table01
(
id number(16),
add_date date default sysdate,
status number(1),
entp_code varchar2(200)
)

 

第二,使用create table table02 as
select * From table01 where id=-1

 

第三、看看兩個表的結構,會發現第二張表的defaule value沒有了,如下2圖,可以很明顯看出來,表02的add_date的默認值得sysdate沒有了

table01的表結構
18b00129-7cb8-310e-8ded-09883d4dedfc.png
table02的表結構


3d783cd3-ca92-378b-b7d8-8b61c4c536c5.png

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章