alter table NC_Account alter column AccountID IDENTITY (1, 1) primary key ("AccountID") NOT NULL不能修改字段为主键与自增长吗

解决方案 »

  1.   

    恩 ,把这列删除掉,新加个identity列
      

  2.   

    alter table 
    drop column AccountID 
    go
    alter table 
    add AccountID int identity(1,1) primary key
      

  3.   

    create table tb(id int,name varchar(50))
    insert into tb select 1,'a'
    insert into tb select 3,'b'
    insert into tb select 5,'c'
    insert into tb select 9,'d'alter table tb drop column id
    alter table tb add id int identity(1,1)select * from tbname id
    a 1
    b 2
    c 3
    d 4
      

  4.   

    alter table NC_Account alter column 只能修改列的数据类型.如果表里面没有数据,可以先把该列删掉然增加该列.
    如果有数据的话,先把该列的数据保存起来,然后删掉该列在增加该列,在把数据导回来
      

  5.   


    或者在企业管理器里面操作,修改字段为标识字段,不是一条sql可以解决的而是一系列的sql语句
      

  6.   

    alter table #t
    drop column AccountID  --删除原来的字段
    go 
    alter table #t
    add AccountID int identity(1,1) primary key --新增字段
      

  7.   

    想直接改就通过企业管理器,或者就是先drop后add具体各位大虾已经写好了