Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding NOT NULL Constraint with ALTER TABLE statement (Oracle)

this is my PL-SQL statement

ALTER TABLE regions MODIFY (region_name VARCHAR(40) DEFAULT 'Euro') CONSTRAINT region_nn NOT NULL;

The column ‘region_name’ has NULL values I want to replace with ‘Euro’. I get an error with this, and I’m wondering if I have the syntax wrong or if it’s impossible to place a default value when adding the NOT NULL constraint and I have to do it as two separate SQL statements

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you for your help’

>Solution :

adding a constrain does not modify any existing data, it only modifies the definition of your table. Fix your data first, then add the constraint – or add the constraint with the defererred keyword and then fix the data. Either way, you’ll manually have to update the data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading