Transferred from:http://jingyan.baidu.com/article/f54ae2fccda68d1e93b84942.html
Example:
--Class table
CREATE TABLE number VARCHAR2 (not NULL);
--Add a primary key to the Tclass table
ALTER TABLE ADD CONSTRAINT PRIMARYKEY(cl_id);
---student table
CREATE TABLESTUDENT (st_idVARCHAR2( -),--Single-line comment primary keySt_codeVARCHAR2( -),--UNIQUE ConstraintSt_nameVARCHAR2( -),--non-null constraintSt_age Number, St_birthday DATE,--Default ConstraintsSt_sexVARCHAR2(4),--Add a Check constraintcl_id Number --Add a foreign key (the primary key of the primary table is referenced));
--Add primary key to student table
ALTER TABLE ADD CONSTRAINT PRIMARY KEY (st_id);
--Give Name list non-empty constraint
ALTER TABLE CONSTRAINTnotNULL;
--Add a unique constraint to St_code
ALTER TABLE ADD CONSTRAINT UNIQUE (St_code);
--st_sex can only be male or female
ALTER TABLE ADD CONSTRAINT CHECK (St_sex=' male 'OR st_sex=' female ' );
--st_birthday Default to Sysdate
ALTER TABLE DEFAULT Sysdate;
---adding foreign keys
ALTER TABLE ADD CONSTRAINT FOREIGN KEY REFERENCES Tclass (cl_id);
Oracle syntax example for adding table constraints