怎么实现 给已有的栏位添加默认绑定值 比如一个栏位我要给他绑定 getdate() 谢了

解决方案 »

  1.   

    create default  aa as getdate()
    go
    sp_bindefault aa, 'table.col'这个是错误的 把 aa增加到默认与绑定了 我把aa换成 getdate() 报错
      

  2.   

    alter table tb add default getdate() for aa
      

  3.   

    alter table tb add default getdate() for aa
      

  4.   

    alter table tablename add   constraint   df_table_col   
      default(getdate()) for col
      

  5.   

    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 行)*/
      

  6.   


    aa是一个default,你刚刚建立的,而getdate()只是一个函数如果用
    alter table tb add default getdate() for aa
    sqlserver会自动创建一个default的约束,绑定到字段。但是约束的名称是sqlserver自己生成的
    你也可以指定alter table tb add CONSTRAINT aa default getdate()  for col
      

  7.   

    增加 default 约束即可。