慎用create table as select,一定要注意默認值的問題


再做一些數據遷移時候,很多人會使用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的表結構

 

table02的表結構

所以各位在做數據庫遷移時候,使用create table as select時候,一定要注意默認值的問題

轉自【http://wmcxy.iteye.com/blog/1137179


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。