if object_id('tempdb..#')is not null drop table # go create table #([name] varchar(10) primary key) insert # select 'A' insert # select 'D' insert # select 'C' insert # select 'B' alter table # add [date] datetime default dateadd(year,100,getdate()) go insert #([name]) select 'E' select * from # /*name date ---------- ------------------------------------------------------ A NULL B NULL C NULL D NULL E 2108-12-30 09:51:21.467*/
create table tb(id int, dt datetime default dateadd(year,100,getdate())) insert into tb(id) values(1) insert into tb(id) values(2) insert into tb(id) values(3) insert into tb(id) values(4) insert into tb(id) values(5) goselect * from tbdrop table tb/* id dt ----------- ------------------------------------------------------ 1 2108-12-30 09:54:39.060 2 2108-12-30 09:54:39.060 3 2108-12-30 09:54:39.060 4 2108-12-30 09:54:39.060 5 2108-12-30 09:54:39.060(所影响的行数为 5 行)*/
你这样是正确的, insert into table (field1,field2,enddate) values ('abc','123',DateAdd(Year,100,GetDate()))
go
create table #([name] varchar(10) primary key)
insert # select 'A'
insert # select 'D'
insert # select 'C'
insert # select 'B'
alter table #
add [date] datetime default dateadd(year,100,getdate())
go
insert #([name]) select 'E'
select * from #
/*name date
---------- ------------------------------------------------------
A NULL
B NULL
C NULL
D NULL
E 2108-12-30 09:51:21.467*/
insert into tb(id) values(1)
insert into tb(id) values(2)
insert into tb(id) values(3)
insert into tb(id) values(4)
insert into tb(id) values(5)
goselect * from tbdrop table tb/*
id dt
----------- ------------------------------------------------------
1 2108-12-30 09:54:39.060
2 2108-12-30 09:54:39.060
3 2108-12-30 09:54:39.060
4 2108-12-30 09:54:39.060
5 2108-12-30 09:54:39.060(所影响的行数为 5 行)*/
insert into table (field1,field2,enddate)
values
('abc','123',DateAdd(Year,100,GetDate()))