ORACLECTAS(createtableasselect)使用注意点看到这篇文章BewareofdefaultvalueswhenusingCTAS,关于createtableasselect(CTAS)值得注意的地方:使用这条sql创建的表不会带默认值。操作以下实验证明之:scott@TICKET>;createtablep2(idnumberprimarykey,3usernamevarchar(25),4passwdvarchar(24),5emailvarchar(30),6birthdate,7telnumber,8sexchar(1));表已创建。scott@TICKET>;altertablepaddagenumber;表已更改。创建一个唯一约束scott@TICKET>;altertablepmodifytelunique;表已更改。创建一个检查约束scott@TICKET>;altertablepaddconstraintp_ck_agecheck(age>;0andage<;150);表已更改。创建一个默认约束scott@TICKET>;altertablepmodifysexdefault'0';表已更改。scott@TICKET>;descuser_constraints;名称是否为空?类型-----------------------------------------------------------------------------OWNERNOTNULLVARCHAR2(30)CONSTRAINT_NAMENOTNULLVARCHAR2(30)CONSTRAINT_TYPEVARCHAR2(1)TABLE_NAMENOTNULLVARCHAR2(30)SEARCH_CONDITIONLONGR_OWNERVARCHAR2(30)R_CONSTRAINT_NAMEVARCHAR2(30)DELETE_RULEVARCHAR2(9)STATUSVARCHAR2(8)DEFERRABLEVARCHAR2(14)DEFERREDVARCHAR2(9)VALIDATEDVARCHAR2(13)GENERATEDVARCHAR2(14)BADVARCHAR2(3)RELYVARCHAR2(4)LAST_CHANGEDATEINDEX_OWNERVARCHAR2(30)INDEX_NAMEVARCHAR2(30)INVALIDVARCHAR2(7)VIEW_RELATEDVARCHAR2(14)查看原表中的各种约束信息.scott@TICKET>;selectconstraint_name,constraint_type,statusfromuser_constraintswheretable_name='P';CONSTRAINT_NAMECSTATUS---------------------------------------SYS_C0015996PENABLEDSYS_C0015997UENABLEDP_CK_AGECENABLED通过查询创建相关的表信息.scott@TICKET>;createtablepersionasselect*fromp;表已创建。scott@TICKET>;select*frompersion;未选定行scott@TICKET>;insertintopersionselect*fromp;已创建0行。检查新表中的约束信息scott@TICKET>;selectconstraint_name,constraint_type,statusfromuser_constraintswheretable_name='PERSION';未选定行再次证明了使用CTAS存在一些问
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
.Oracle查询了一下文档(11gr1),关于ASsubquery里面叙述到OracleDatabaseautomaticallydefinesoncolumnsinthenewtableanyNOTNULLconstraintsthatwereexplicitlycreatedonthecorrespondingcolumnsoftheselectedtableifthesubqueryselectsthecolumnratherthananexpressioncontainingthecolumn.Ifanyrowsviolatetheconstraint,thenthedatabasedoesnotcreatethetableandreturnsanerror.显示的NOTNULL约束自动会带到新表。NOTNULLconstraintsthatwereimplicitlycreatedbyOracleDatabaseoncolumnsoftheselectedtable(forexample,forprimarykeys)arenotcarriedovertothenewtable.隐式的NOTNULL约束不会带到新表,如主键。Inaddition,primarykeys,uniquekeys,foreignkeys,checkconstraints,partitioningcriteria,indexes,andcolumndefaultvaluesarenotcarriedovertothenewtable.另外,主键,唯一,外键,check约束,分区,索引以及列的默认值不会带到新表。Iftheselectedtableispartitioned,thenyoucanchoosewhetherthenewtablewillbepartitionedthesameway,partitioneddifferently,ornotpartitioned.Partitioningisnotcarriedovertothenewtable.SpecifyanydesiredpartitioningaspartoftheCREATETABLEstatementbeforetheASsubqueryclause.在新表上可以选择是否像像旧表那样分区,或者不同的分区形式,或者创建非分区表。在ASsubquery句之前指定。