create default aa as getdate() go sp_bindefault aa, 'table.col'这个是错误的 把 aa增加到默认与绑定了 我把aa换成 getdate() 报错
alter table tb add default getdate() for aa
alter table tb add default getdate() for aa
alter table tablename add constraint df_table_col default(getdate()) for col
1.直接在列的属性里面,默认值那个地方修改为:getdate() 2.用语句的话,则如下: create table tb(id int , dt datetime) goalter table tb add default getdate() for dt goinsert into tb(id) values(1)select * from tbdrop table tb/*id dt ----------- ------------------------------------------------------ 1 2010-04-26 11:57:07.013(所影响的行数为 1 行)*/
aa是一个default,你刚刚建立的,而getdate()只是一个函数如果用 alter table tb add default getdate() for aa sqlserver会自动创建一个default的约束,绑定到字段。但是约束的名称是sqlserver自己生成的 你也可以指定alter table tb add CONSTRAINT aa default getdate() for col
go
sp_bindefault aa, 'table.col'这个是错误的 把 aa增加到默认与绑定了 我把aa换成 getdate() 报错
default(getdate()) for col
2.用语句的话,则如下:
create table tb(id int , dt datetime)
goalter table tb add default getdate() for dt
goinsert into tb(id) values(1)select * from tbdrop table tb/*id dt
----------- ------------------------------------------------------
1 2010-04-26 11:57:07.013(所影响的行数为 1 行)*/
aa是一个default,你刚刚建立的,而getdate()只是一个函数如果用
alter table tb add default getdate() for aa
sqlserver会自动创建一个default的约束,绑定到字段。但是约束的名称是sqlserver自己生成的
你也可以指定alter table tb add CONSTRAINT aa default getdate() for col