Home » SQL & PL/SQL » SQL & PL/SQL » How to create named DEFAULT constraint (Oracle SQL)
How to create named DEFAULT constraint [message #642588] Tue, 15 September 2015 04:04 Go to next message
battaarchana
Messages: 8
Registered: September 2015
Junior Member
Hi Everyone,

Can you please help me in creating named DEFAULT constraint?For ex, i have customers table with fields ID,Name,ADDRESS,SALARY and AGE. Now, i want to alter this table by adding a named DEFAULT constraint for SALARY and AGE.

This is something which i tried and didnt work.
ALTER TABLE customers
ADD CONSTRAINT mydef_const DEFAULT 25 for AGE;

can you please correct me if i am wrong.

Thanks & Regards,
B Archana.
Re: How to create named DEFAULT constraint [message #642591 is a reply to message #642588] Tue, 15 September 2015 04:10 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Defaults aren't constraints - they don't appear in user_constraints and don't have a constraint_type.
So no there's no way to name them or create them with ADD CONSTRAINT.
Re: How to create named DEFAULT constraint [message #642592 is a reply to message #642588] Tue, 15 September 2015 04:10 Go to previous messageGo to next message
John Watson
Messages: 8930
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

Do you want to add a constraint, or a defualt, or both? THey are not the same thing.
Re: How to create named DEFAULT constraint [message #642593 is a reply to message #642588] Tue, 15 September 2015 04:12 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
DEFAULT is not a constraint, it is a value.
SQL> create table test
  2  (id  number,
  3   age number
  4  );

Table created.

SQL> alter table test modify age default 25;

Table altered.

SQL>
Re: How to create named DEFAULT constraint [message #642864 is a reply to message #642593] Tue, 22 September 2015 03:25 Go to previous message
battaarchana
Messages: 8
Registered: September 2015
Junior Member
Hello All,

Thanks for your time.
I understood what you mean by DEFAULT is not a constraint. It is the way i thought is something wrong.
Yes, as you said DEFAULT is not a constraint.

Thanks & Regards,
B Archana.
Previous Topic: Simple procedure
Next Topic: Get Max Value of Date Column With Condition
Goto Forum:
  


Current Time: Tue Apr 23 14:57:26 CDT 2024