///copy the primary key sql> create table asp(no number primary key); table created. sql> desc asp; name
null?
-------------------------no not null -------------------------------------------------------copy the asp table to asp1 -------------------------------------------------------sql> create table asp1 as select * from asp; table created. sql> desc asp1; name
null?
-------------------------no -------------------------------------------------------can't copy the primary ker to asp1 -------------------------------------------------------//copy the not null sql> create table asp(no number not null); table created. sql> desc asp; name
null?
----------------------------------------no not null ----------------------------------------------------------copy the asp table to asp1 ----------------------------------------------------------sql> create table asp1 as select * from asp; table created. sql> desc asp1; name
null?
--------------------------------no not null
----------------------------------------------------not null constraints shuld copy to another table ----------------------------------------------------//unique sql> create table asp(no number unique); table created. sql> desc asp; name
null?
----------------------------no --------------------------------------------copy the table --------------------------------------------sql> create table asp1 as select * from asp; table created. sql> desc asp1; name null? ------------------------------no //insert the value from asp sql> insert into asp values('&no'); enter value for no: 1 old 1: insert into asp values('&no') new 1: insert into asp values('1') 1 row created. sql> / enter value for no: 1 old 1: insert into asp values('&no') new 1: insert into asp values('1') insert into asp values('1') * error at line 1: ora-00001: unique constraint (ponnusamy.sys_c003027) violated sql> / enter value for no: 2 old 1: insert into asp values('&no') new 1: insert into asp values('2') 1 row created.
//insert the values for asp1 sql> insert into asp1 values('&no'); enter value for no: 1 old 1: insert into asp1 values('&no') new 1: insert into asp1 values('1') 1 row created. sql> / enter value for no: 1 old 1: insert into asp1 values('&no') new 1: insert into asp1 values('1') 1 row created. ---------------------------------------------------------------unique constraints should not copy ---------------------------------------------------------------//check constraints sql> create table asp(no number check(no<2)); table created. sql> insert into asp values('&no'); enter value for no: 1 old 1: insert into asp values('&no') new 1: insert into asp values('1') 1 row created. sql> / enter value for no: 2 old 1: insert into asp values('&no') new 1: insert into asp values('2') insert into asp values('2') * error at line 1: ora-02290: check constraint (ponnusamy.sys_c003028) violated sql> / enter value for no: 0 old 1: insert into asp values('&no') new 1: insert into asp values('0') 1 row created. ----------------------------copy the table ----------------------------sql> create table asp1 as select * from asp; table created. sql> insert into asp1 values('&no');
enter value for no: 1 old 1: insert into asp1 values('&no') new 1: insert into asp1 values('1') 1 row created. sql> / enter value for no: 2 old 1: insert into asp1 values('&no') new 1: insert into asp1 values('2') 1 row created. sql> / enter value for no: 3 old 1: insert into asp1 values('&no') new 1: insert into asp1 values('3') 1 row created. sql> select * from asp1; no ---------1 0 1 2 3 ----------------------------------------------------check constraints shoult not copy ------------------------------------------------------