There are 5 types of---Constraints: PRIMARY key foreign key unique non-NULL check 5 class constraints
Column-level constraints and table-level constraints in Oracle
Column-level constraints: Columns are then added to the constraint when the table is created
For example:
CREATE TABLE Table11 (Stuno number (2) constraint TABLE_PK primary key,tname varchar2 (5) unique--unique constraint)
The above two fields are the constraints written directly above the columns: Optional [constraint TABLE_PK] primary key,
Table-level constraints:
For example:
--table-level constraint CREATE TABLE Table22 (Idno number (2), Tname varchar2 (5) unique,--UNIQUE constraint price number (5,2) check (price>100),-- Check constraint Stuno number (2), --below the table-level constraint is the constraint TB_2_PK primary key (Idno) under all the shoes columns, constraint TB_2_FK foreign key ( Stuno) references Table11 (Stuno))
Add a constraint called table-level constraint below all fields
----------------Modifying a table
ALTER TABLE TABLE22 drop [column name,,,]--delete column ALTER TABLE TABLE22 add column name type [default value]--add column ALTER TABLE table22 modify column name Type [default]--Modify Column
--------Adding table-level constraints
ALTER TABLE TABLENAMEADD constraint TABLE_PK primary key (ID);--Add primary key ALTER TABLE Tablenamedrop table_pk;--Delete primary key
------To modify a constraint on a column
ALTER TABLE tablename Modify column name constraint Notnull not null;--add non-null constraint ALTER TABLE tablename modify column name constraint Check2 CHEC K (column name >1200);--check constraint
-----To remove a constraint for a column
ALTER TABLE tname DROP constraint constraint name;--delete ALTER TABLE Tname modify column name by constraint name null;--Delete non-null constraint
Oracle about defining constraints/modifying table structures/modifying constraints