Create a new table using an existing table
CREATE TABLE JOBS_Temp AS SELECT * FROM HR.JOBS
Table created.
Display the table information
SELECT * FROM JOBS_Temp WHERE MIN_SALARY < 3000
JOB_ID | JOB_TITLE | MIN_SALARY | MAX_SALARY | PU_CLERK | Purchasing Clerk | 2500 | 5500 | ST_CLERK | Stock Clerk | 2008 | 5000 | SH_CLERK | Shipping Clerk | 2500 | 5500 |
---|
Add a constraint to the table
ALTER TABLE JOBS_Temp ADD CONSTRAINT chk_sal_min CHECK (MIN_SALARY >=2010)
ORA-02293: cannot validate (SQL_AXFPHFCOGWWGPCCDQBLNJZJYT.CHK_SAL_MIN) - check constraint violatedMore Details: https://docs.oracle.com/error-help/db/ora-02293
Update the table column where we added a constraint
UPDATE JOBS_Temp SET MIN_SALARY = 2300 WHERE MIN_SALARY < 2010
1 row(s) updated.
Adding the constraint to the column
ALTER TABLE JOBS_Temp ADD CONSTRAINT chk_sal_min CHECK (MIN_SALARY >=2010)
Table altered.
Display the table information
SELECT * FROM JOBS_Temp WHERE MIN_SALARY < 3000
JOB_ID | JOB_TITLE | MIN_SALARY | MAX_SALARY | PU_CLERK | Purchasing Clerk | 2500 | 5500 | ST_CLERK | Stock Clerk | 2300 | 5000 | SH_CLERK | Shipping Clerk | 2500 | 5500 |
---|
Display the contraints in the table
SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME='JOBS_TEMP'
CONSTRAINT_NAME | SYS_C002709353 | CHK_SAL_MIN |
---|