alter table tablename alter column columnname set default 'value'在网上看的关于default约束,但是会报“关键字 'set' 附近有语法错误。”的错误出来。
大家帮忙看下。

解决方案 »

  1.   

    alter table tablename alter column columnname default 'value' 
      

  2.   

    #1正确
    alter table tablename alter column columnname default 'value'
      

  3.   

    Create table tablename(columnname nvarchar(50))
    go
    alter table tablename add constraint UQ_tablenam_columnname default 'value' for columnname;
      

  4.   

    关键字 'default' 附近有语法错误。
      

  5.   


    if object_id('tb','U') is not null
       drop table tb
    go
    create table tb
    (
     id int identity(1,1),
     name varchar(10)
    )
    go
    alter table tb add constraint tb_name_def default 'abc' for name
      

  6.   

    [ CONSTRAINT constraint_name ] 

        { PRIMARY KEY | UNIQUE } 
            [ CLUSTERED | NONCLUSTERED ] 
            (column [ ASC | DESC ] [ ,...n ] )
            [ WITH FILLFACTOR =fillfactor 
            [ WITH ( <index_option>[ , ...n ] ) ]
            [ ON { partition_scheme_name (partition_column_name ... )
              | filegroup | "default" } ] 
        | FOREIGN KEY 
            (column [ ,...n ] )
            REFERENCES referenced_table_name [ ( ref_column [ ,...n ] ) ] 
            [ ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ] 
            [ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ] 
            [ NOT FOR REPLICATION ] 
        | DEFAULT constant_expression FOR column [ WITH VALUES ] 
        | CHECK [ NOT FOR REPLICATION ] (logical_expression )
    }
      

  7.   

    alter table tb add constraint XXOO default 'xx' for oo
    --就是加了一个约束,默认值也是一种约束
      

  8.   

    如果改变的话需要先删除了alter table tb drop  XXOOalter table tb add constraint XXOO default 'xoxo' for oo