--5 constraints, PRIMARY KEY constraints, FOREIGN KEY constraints, UNIQUE constraints, check constraints, non-null constraints.
--Add PRIMARY KEY constraint Alter table table_name add constraints Constraint_name Primary key (column_name);
--Syntax description constraint_name: Constraint name. COLUMN_NAME: PRIMARY KEY constraint specifies the column name in the data table.
--Remove the PRIMARY KEY constraint Alter table table_name Drop constraint constraint_name;
--FOREIGN KEY constraint
--Add a FOREIGN key constraint directly in the table, and you need to add the following statement to the last side as you create it
Constraint constraint_name foreign key (COLUMN_NAME) reference table_name (column_name) on DELETE cascade;
--Syntax Description constraint_name: The name of the foreign KEY constraint.
Foreign KEY (column_name): Specifies the column name of the foreign KEY constraint.
Reference: The table name (column name) that needs to be referenced.
On DELETE CASCADE: Set cascade Delete, when the primary key bullet is deleted, the field corresponding to the foreign key is also deleted.
--Add a FOREIGN key constraint directly after creating the table
Alter table table_name Add constraint constraint_name foreign key (COLUMN_NAME) reference table_name (COLUMN_NAME) on Delet e Cascade;
--delete foreign KEY constraint
Alter table table_name drop constraint constraint_name;
--check constraints
--When creating a table, add a check constraint and add a constraint directly behind the field
Constraint constraint_name Check (condition);
Condition: is the condition for checking constraints.
--alter Table Add Check Constraint
Alter table table_name ADD constraint constraint_name check (condition);
--delete Check constraint Alter
Table table_name Drop constraint constraint_name;
--unique constraints, UNIQUE constraints,
CREATE TABLE adds UNIQUE constraint constraint constraint_name unique (column_name);
--Add a unique constraint when modifying a table
Alter table table_name ADD constraint constraint_name unique (column_name);
--The only constraint to remove a table
Alter table table_name Drop constraint constraint_name;
--Create non-null constraints, add non-null constraints directly when creating tables
... not NULL,
--Add a non-null constraint when modifying a table
Alter Table table_name Modify column_name NOT NULL;
--truncate completely deletes the table and cannot be recovered after deletion.
TRUNCATE TABLE table_name;
--merge statements, batch modification and bulk increment statements
Merge [into] table_name1 using table_name2 on (condition) while matched then merge_update_clause when not matched then Mer Ge_insert_clause; --Syntax Description table_name1: The table to be modified or added.
Table_name2: Reference to the Update table. The relationship between CONDITION:TABLE_NAME1 and TABLE_NAME, or some other condition. Merge_update_clause: The update operation is performed if the conditions in the reference table table_name2 are matched. (Update set Column_name1=column_name2) Merge_insert_clause: Performs a new operation if the condition does not match. (INSERT INTO (column_name2,column_name2,...))
Use of Oracle Constraints