首先进入企业管理器,将表格子段属性更改为非空,选中需要更改的表格,右键--〉
设计表,选中主键字段,将“允许空“复选框取消,然后保存
执行完毕然后更改为主键
确保没有空值null和重复键值
祝你好运!!!

解决方案 »

  1.   

    alter table yourtable alter column colname int identity(1,1) not null
      

  2.   

    如果有空记录的话,首先应该干掉空记录,然后在可以使用修改语句
    if exits( select count(column) from table  where column_null  is null) 
       --看者办--
    alter table table alter column column_null not null
    alter table table add constrant pk_table primary key ( column_null )
      

  3.   

    hjb111(唐老鸭) 的有语法错误,没有alter table TABLENAME alter column 这种语句。
      

  4.   

    alter table TABLENAME drop column a 
    alter table TABLENAME add a int identity(1,1) not null
    alter table TABLENAME add constraint PK_game primary key(a)
      

  5.   

    对不起,hjb111(唐老鸭),我出现了失误,有alter table tablename alter column 语句。
    please forgive me.
      

  6.   

    赞同LIONSTAR(小狮子)的做法