sql server - How can I set the date of every row in a table to the current date? -
i have sql server table:
create table [dbo].[synonym] ( [synonymid] [int] not null, [wordformid] [int] not null, [ascii] (ascii([text])) persisted, [text] [varchar](max) not null, [version] [timestamp] null, [createdby] [int] null, [createddate] [datetime] null, [modifiedby] [int] null, [modifieddate] [datetime] null, primary key clustered ([synonymid] asc) (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] ) on [primary] textimage_on [primary]
how can set createddate current date of rows?
if want save date when record created, add default constraint table:
alter table [synonym] add constraint createddate default getdate() [createddate]
then if insert record don't need specify createddate , current date value.
if want set date existing records run update
update [synonym] set [createddate] = getdate()
or records createddate
null:
update [synonym] set [createddate] = getdate() [createddate] null
Comments
Post a Comment