1. Non-null (NOT NULL) constraint: The defined column is not absolutely null;
For example, modify the BookName field in the created table book to Be not empty:
Use ALTER TABLE .... MODIFY ..... Not NULL;
ALTER TABLE not NULL;
2. Primary key (PRIMARY key) constraint: A unique identifier for each row in the table;
For example: Add a primary key named "BOOK_PK" for the BookID field in the Created table book
Use Alter TABLE ..... ADD CONSTRAINT book_pk PRIMARY KEY (field);
ALTER TABLE ADD CONSTRAINT PRIMARY KEY (BookID);
3. Unique constraint: The value of each column field cannot be the same;
Example: Add a unique constraint to the Phone field in table Usertable
Use Alter TABLE ..... ADD CONSTRAINT book_pk PRIMARY KEY (field);
ALTER TABLE ADD CONSTRAINT Unique (phone);
4. Foreign key (FOREIGN key) constraint: Used to maintain referential integrity between the table and the primary table;
For example, dept is the primary table, the EMP is from the table (foreign key table), and the foreign key column in the EMP deptno references the key in dept
ALTER TABLE ADD CONSTRAINT FOREIGN KEY REFERENCES Dept (DEPTNO);
Cascade Delete: When the referenced column in the reference table (primary table) is deleted, the corresponding data in the foreign key table is also deleted (implemented as follows)
ALTER TABLE ADD CONSTRAINT FOREIGN KEY REFERENCES on DELETE CASCADE;
5. Condition (CHECK) constraint: The constraint is met for each row in the table.
For example, to create a given student table (Student), define a CHECK constraint (age>0 and age<120) for the Age column (ages) for the Disable state (some of the code when the table is built is as follows:)
int constraint Check (age>0 and age<disable),
Five types of constraints for Oracle