-1

This throws an error:

ALTER TABLE TABLE_NAME 
   ADD CONSTRAINT UC_Person NOT NULL(AGE); 

This works fine:

ALTER TABLE TABLE_NAME 
    MODIFY Column_name data_type not null;

Question is that 1st one why getting the error and for unique will not get an error.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Naveen kumar
  • 1
  • 1
  • 1

1 Answers1

1

Why? Because you can't just make up syntax the way you'd want it to be - it is here so that you'd follow it.

If you want to name the NOT NULL constraint, then do it as follows:

SQL> create table table_name (age number);

Table created.

SQL> alter table table_name modify age constraint uc_person not null;

Table altered.

SQL>

It gets simpler if you don't care about constraint name:

SQL> drop table table_name;

Table dropped.

SQL> create table table_name (age number);

Table created.

SQL> alter table table_name modify age not null;

Table altered.

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57