SQL 16
SQL 16
syntax:
create table tablename(col1 datatype(size) check(logical
cond) col2 datatype(size),...);
column level:
SQL> create table test(sal number(10) check(sal>2000));
Table created.
1 row created.
Table created.
1 row created.
NAME
----------
ABC
1 row created.
table level:
syntax:
create table tablename(col1 datatype(size),col2 datatype(size)
check(cond1,cond2));
Table created.
1 row created.
Table created.
1 row created.
1 row created.
CONSTRAINT_NAME C
------------------------------ -
SYS_C0012048 P
Table altered.
SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE from user_constraints
2 where table_name='TEST';
CONSTRAINT_NAME C
------------------------------ -
SYS_C0012048 P
SYS_C0012049 U
desc user_constraints;
note:
if you want to add not null constraint on existing table
,existing column then we are using alter with modify
syntax:
alter table tabelname modify columnname not null;
Table altered.
dropping constrainsts:
syntax:
alter drop tablename drop constraint constraintname;
syntax:
alter table tablename drop primary key;
syntax:
alter table tablename drop unique(col1,col2.....)
Table altered.
note:
we cannot drop master table directly after dropping child
table only we can drop master table
SQL> drop table child;
Table dropped.
Table dropped.
note:
if you want to drop primary key along with referenced foreign
key then we are using cascade along with alter drop
syntax:
alter table tablename drop primary key cascade;
Table created.
Table created.
Table altered.
Table dropped.