Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Set Default value to Column in Table using alter

Author  Topic 

Praveen Kandasamy
Starting Member

4 Posts

Posted - 2015-04-25 : 05:25:50
How to set a default value to columns in table ..without dropping it.??

Thanx in Advance

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2015-04-25 : 05:32:33
alter table yourtablename
alter column yourcolumnname set default 'yourdefaultvalue'
Go to Top of Page

Praveen Kandasamy
Starting Member

4 Posts

Posted - 2015-04-25 : 05:39:28
Thanks bitsmed ...

This is my alter statement
alter table ROLEMASTER
alter column ISSYSTEMGENERATED set default 'MSC003'

when i run this query. its shows error

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'set'.
Go to Top of Page

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2015-04-25 : 05:49:58
Sorry, my mistake. The syntax is:
alter table yourtablename
add constraint yourconstraintname default yourdefaultvalue for yourcolumnname

So in your case:
alter table ROLEMASTER
add constraint def_rolemaster_sysgen default 'MSC003' for ISSYSTEMGENERATED
Go to Top of Page
   

- Advertisement -