千家信息网

【实验】验证通过create table as select 方式无法创建主键小实验

发表于:2024-11-30 作者:千家信息网编辑
千家信息网最后更新 2024年11月30日,sec@ora10g> create table test1 ( a number primary key, b number not null);Table created.sec@ora10g>
千家信息网最后更新 2024年11月30日【实验】验证通过create table as select 方式无法创建主键小实验sec@ora10g> create table test1 ( a number primary key, b number not null);

Table created.

sec@ora10g> desc test1;
Name Null? Type
---------------------- -------- ------------------
A NOT NULL NUMBER
B NOT NULL NUMBER

sec@ora10g> insert into test1 values (1,1);

1 row created.

sec@ora10g> insert into test1 values (2,2);

1 row created.

sec@ora10g> COMMIT;

Commit complete.

sec@ora10g> create table test2 as select * from test1;

Table created.

sec@ora10g> desc test2;
Name Null? Type
--------------------- -------- ------------------
A NUMBER
B NOT NULL NUMBER

sec@ora10g> select * from test1;

A B
---------- ----------
1 1
2 2

sec@ora10g> select * from test2;

A B
---------- ----------
1 1
2 2

0