sql server - Alter column, add default constraint -


i have table , 1 of columns "date" of type datetime. decided add default constraint column

alter table tablename alter column dbo.tablename.date default getutcdate()  

but gives me error:

incorrect syntax near '.'

does see wrong here, missing (other having better name column)

try this

alter table tablename   add constraint df_constraintname   default getutcdate() [date] 

example

create table bla (id int)  alter table bla add constraint dt_bla default 1 id    insert bla default values  select * bla 

also make sure name default constraint..it pain in neck drop later because have 1 of crazy system generated names...see how name default constraints , how drop default constraint without name in sql server


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -