SQL Server CE : alter column Token in error = DEFAULT - sql

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]

Related

How to set a default value for a column in SQL Server when changing the column's data type?

I want to change the data type of a column from integer to datetime in an SQL Server database.
The column contains NULL values only.
This works:
ALTER TABLE tablename ALTER COLUMN columnname DATETIME
However this doesn't:
ALTER TABLE tablename ALTER COLUMN columnname DATETIME DEFAULT NULL
I would like to know why exactly this doesn't work.
I know that it is possible to add a default value with this command afterwards:
ALTER TABLE tablename ADD CONSTRAINT DF_SomeName DEFAULT NULL FOR columnname
But is there a way to change the data type and add a default value with just one command?
EDIT: I have to do this in a Sybase db as well and there it works like this:
ALTER TABLE tablename MODIFY columnname DATETIME DEFAULT NULL

Add a generated column using alter table statement

I'm not able to add a generated column using an alter table statement in SQL Server 2017. I'm trying to create a temporal table from an existing table as discussed in the following link: https://learn.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table?view=sql-server-ver15
But alter table shows an error:
Incorrect syntax near generated
GO
ALTER TABLE InsurancePolicy
ADD SysStartTime DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN
CONSTRAINT DF_SysStart DEFAULT SYSUTCDATETIME() , SysEndTime DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN CONSTRAINT DF_SysEnd DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'),
PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime);
GO
ALTER TABLE InsurancePolicy SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = History.InsurancePolicy));

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.

Alter column with default constraint in Oracle

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

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