THE SCENARIO I am working on an educational problem in which I need to convert some 'NOT NULL' constraints into 'NULL's and vice-versa.
PREVIOUS RESEARCH I have read up a few sources that tell me /how/ I can do this (with methods that I will describe below) but they don't explain why I would want to use a seemingly longer and more convoluted method over a seemingly faster method.
- How can I drop a "not null" constraint in Oracle when I don't know the name of the constraint?
- How to fetch the system generated check constraint name of table column in oracle
THE PROBLEM I've been instructed to query the table that I want to amend as follows:
SELECT constraint_name, constraint_type
FROM all_constraints
WHERE table_name = 'FILM'
AND owner = 'SAKILA'
This gives me all the constraints on the table including what appear to be a bunch of constraints that were automatically created by the database:
FK_FILM_LANGUAGE
FK_FILM_LANGUAGE_ORIGINAL
PK_FILM
SYS_C00738336
SYS_C00738337
SYS_C00738338
SYS_C00738339
SYS_C00738340
I am then being instructed to manually work out which SYS_**** relates to which item in the table and then manually drop those constraints and write in new ones as follows:
ALTER TABLE film DROP CONSTRAINT SYS_C00738336;
ALTER TABLE film ADD CONSTRAINT constraint_name;
CONSTRAINT complete_nn CHECK (complete IS NOT NULL);
What I'm struggling to understand is why do I have to go through all of that when it appears that I can just use a 'modify' statement such as:
alter table
film
modify
(film_title NOT NULL);
My understanding is that if you set something to 'NOT NULL' when you create it, the system automatically generates the constraint and that you don't need to manually drop it, which would save me quite a lot of time as there are a fairly large number of NULL and NOT NULL values that need to be altered.
Thank you in advance for any help you're able to provide.