Alter column with default constraint in Oracle - sql

This works fine in SQL Server.
ALTER TABLE HS_HR_PEA_EMPLOYEE
ADD CONSTRAINT SET_ADDED_TIME_AUTOMATICALLY DEFAULT GETDATE() FOR JS_PICKED_TIME
What is the Oracle equivalent query for this?

Just add DEFAULT current date for your column
ALTER TABLE HS_HR_PEA_EMPLOYEE MODIFY JS_PICKED_TIME DATE DEFAULT SYSDATE

Related

Unable to drop default constraint in 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.
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;
Use MODIFY [COL_NAME] DEFAULT NULL instead of ALTER COLUMN [COL_NAME] DROP DEFAULT so far oracle does not accept the latter version.

SQL Server CE : alter column Token in error = DEFAULT

I am using SQL Server CE and I have a table [accounts]. I was modifying the column [ondate] so that it can have a default of GetDate.
My query is
ALTER TABLE [accounts]
ALTER COLUMN [ondate] DATETIME NULL DEFAULT GETDATE()
But I get this error :
Token in error = DEFAULT
I have tried getdate without parenthesis, with single quotes (') but the error is still the same.
How to modify the column [ondate] to have default of getdate?
Here is the correct syntax
ALTER TABLE accounts ADD DEFAULT getdate() FOR [ondate]
It is always better to add a name to constraints
ALTER TABLE accounts ADD CONSTRAINT DF_ONDATE_GETDATE DEFAULT getdate() FOR [ondate]
This will work for you
Alter Table [accounts] ADD DEFAULT getdate() for [ondate]

How to set default value using alter table statement in sql server 2008

I want to set default value constraint
I have written the following sql
ALTER TABLE vote
ADD CONSTRAINT deVote DEFAULT false FOR status
But it's giving error: Column names are not permitted
What I am doing wrong. Help
Thanks
If column is a VARCHAR data type
ALTER TABLE vote
ADD CONSTRAINT df_devote_default DEFAULT 'false' FOR [status];
If column is a BIT data type
ALTER TABLE vote
ADD CONSTRAINT df_devote_default DEFAULT 0 FOR [status];
Try this:
ALTER TABLE vote ADD CONSTRAINT deVote DEFAULT N'false' FOR status;
ALTER TABLE vote
ALTER deVote SET DEFAULT 'false' FOR status

Need to add constraint: date plus 10 days

I'm trying to add a constraint to a table so that it displays one of the columns as the current date plus 10 days. Here's what I've tried so far (I'm very new to SQL):
ALTER TABLE orders
ADD CONSTRAINT default_date
DEFAULT DATEADD (DAY,10,required_date) FOR required_date
Halp!
Edit: I've also tried this now:
ALTER TABLE orders
ALTER COLUMN required_date
ADD CONSTRAINT required_date_plus_ten
DEFAULT DATEADD (DAY,10,required_date)
Edit: Thanks to ypercube & my classmate. The final code is:
ALTER TABLE orders
ADD CONSTRAINT default_date
DEFAULT (DATEADD (DAY,10,'required_date')) FOR required_date;
The syntax in SQL-Server, for adding a DEFAULT value to an existing column is:
ALTER TABLE orders
ADD CONSTRAINT required_date_plus_ten
DEFAULT DATEADD(day, 10, GETDATE())
FOR required_date ;
Tested in SQL-Fiddle

how to remove default constraint from column in Db2

I had a table STUDENT_TB, which had column STUDENT_ID, NAME, AGE. I added a column with a following command :-
alter table STUDENT_TB add DOB TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP
as for the DOB column i didn't wanted it to be null. Now i need to remove that default constraint.
I tried searching but not got any success.
Regards.
I tried with this and it worked properly
alter table STUDENT_TB alter DOB drop DEFAULT
ALTER TABLE STUDENT_TB ALTER COLUMN DOB DROP NOT NULL