create table as 复制not null
Posted 会飞的板儿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了create table as 复制not null相关的知识,希望对你有一定的参考价值。
创建一张表包含非空约束,唯一约束和check约束
SQL> create table dept(
2 ename varchar2(20) constraint mep_ename_nn not null,
3 email varchar2(30) constraint mep_email_uk unique,
4 constraint emp_email_ck check ((instr(email,‘@‘)>0)));
Table created.
查看约束情况:
SQL> select constraint_name,constraint_type,column_name
2 from user_constraints natural join user_cons_columns
3 where table_name=‘DEPT‘;
CONSTRAINT_NAME C COLUMN_NAME
------------------------------ - ---------------
MEP_ENAME_NN C ENAME
EMP_EMAIL_CK C EMAIL
MEP_EMAIL_UK U EMAIL
使用create table as语句创建另外一张表:
SQL> create table dept_test as select * from dept;
Table created.
检查约束情况,只有ename上的nut null约束被复制了过来
SQL> select constraint_name,constraint_type,column_name
2 from user_constraints natural join user_cons_columns
3 where table_name=‘DEPT_TEST‘;
CONSTRAINT_NAME C COLUMN_NAME
------------------------------ - ---------------
SYS_C0011591 C ENAME
尝试插入数据报错
SQL> insert into dept_test(email) values(‘[email protected]‘);
insert into dept_test(email) values(‘[email protected]‘)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("SYS"."DEPT_TEST"."ENAME")
以上是关于create table as 复制not null的主要内容,如果未能解决你的问题,请参考以下文章
何时将 CREATE TABLE AS SELECT 与 CREATE TABLE LIKE?
oracle数据库表复制insert into select from跟create table as select * from 两种表复制语句区别
create table as 和create table like的区别
mysql复制表结构create table as和like的区别