Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to drop default constraint in Oracle

Tags:

sql

oracle

SQL> ALTER TABLE CUSTOMERS MODIFY AGE INT DEFAULT 10;

Table altered.

SQL > ALTER TABLE CUSTOMERS ALTER COLUMN AGE DROP DEFAULT;

ERROR at line 2:
ORA - 01735 : invalid ALTER TABLE OPTION.
like image 715
Masud Shaik Avatar asked Nov 08 '16 07:11

Masud Shaik


People also ask

How do I drop a DEFAULT constraint?

How to Remove Default Constraints in SQL? To remove an existing DEFAULT constraint on any column, you can use the ALTER TABLE statement along with the DROP keyword in SQL. ALTER TABLE is used because the table is being modified or altered, and DROP is used to remove the constraint from the column of the table.

How to remove DEFAULT in Oracle?

How to drop a column's default value? The following commands fails: ALTER TABLE t1 ALTER COLUMN c1 DROP DEFAULT. ALTER TABLE t1 MODIFY c1 DROP DEFAULT.

Can we drop primary key constraint in Oracle?

To drop a primary key from a table, use an ALTER TABLE clause with the name of the table (in our example, product ) followed by the clause DROP PRIMARY KEY . Since a table can have only one primary key, you don't need to specify the primary key column(s).


1 Answers

Your ALTER statement is wrong and you cannot use two ALTER commands in one statement. And we never drop default value instead we set it to NULL.

If a column has a default value, then you can use the DEFAULT clause to change the default to NULL, but you cannot remove the default value completely. If a column has ever had a default value assigned to it, then the DATA_DEFAULT column of the USER_TAB_COLUMNS data dictionary view will always display either a default value or NULL.

ALTER TABLE

Use the following SQL command to drop the default.

ALTER TABLE constomers MODIFY age DEFAULT NULL;
like image 93
atokpas Avatar answered Oct 20 '22 11:10

atokpas