Alter table dbo.aqgj_dm drop Column idAlter talbe dbo.aqgj_dm Add id int identity

解决方案 »

  1.   

    ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
    go
    SET IDENTITY_INSERT 表 ON
    go
    update 表 set 编号1=编号
    go
    SET IDENTITY_INSERT 表 OFF
    go
    ALTER TABLE 表 DROP COLUMN 编号 
    go
    exec sp_rename '表.编号1','编号'
    go
      

  2.   

    ID为主键不能够删除。
    我做数据传输,将Acess 中的表到入到SQL Server 中,到入时id 为int 我必须用语句将起改为种子标识列。
      

  3.   

    先执行:declare @a varchar(20)
    select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('表名') and a.name='主鍵列名' and a.id=b.id and b.constid=c.id and c.name like 'PK%'
    exec('alter table 表名 drop constraint '+@a)来删掉主键
      

  4.   

    不能直接修改为标识列:
    可以先加新的标识列,再设置允许修改标识列,再用原来的字段值填充标识列,再删除原字段,再对字段改名ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
    go
    SET IDENTITY_INSERT 表 ON
    go
    update 表 set 编号1=编号
    go
    SET IDENTITY_INSERT 表 OFF
    go
    ALTER TABLE 表 DROP COLUMN 编号 
    go
    exec sp_rename '表.编号1','编号'
    go
      

  5.   

    大力我写成下面的语句:
    declare @a varchar(20)
    select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('dbo.aqgj_dm') and a.name='id' and a.id=b.id and b.constid=c.id and c.name like 'PK%'
    exec('alter table dbo.aqgj_dm drop constraint '+@a)
    提示:
    服务器: 消息 170,级别 15,状态 1,行 1
    第 1 行: 'constraint' 附近有语法错误。
    请问是什么原因?蚂蚁:程序当执行到
    update 表 set 编号1=编号
    时出错:
    务器: 消息 8102,级别 16,状态 1,行 1
    无法更新标识列 'id1'。
    我该怎么办?
      

  6.   

    declare @a varchar(20)
    select @a=c.name from syscolumns a,sysconstraints b,sysobjects 
    c where a.id=object_id('dbo.table1')  and a.name='ab'
    and a.id=b.id and b.constid=c.id 
    and c.name like 'PK%'
    if @a is not null
    exec('alter table dbo.table1 drop constraint '+@a)
      

  7.   

    大力命令以成功执行,(在企业管理器中 id的主键标识去掉)
    我下一步该干什么?
    执行:
    alter table dbo.aqgj_dm alter column id int identity(1,1) not null
    么?
    我执行后还是:在关键字 'IDENTITY' 附近有语法错误。
      

  8.   

    我执行的语句是:
    declare @a varchar(20)
    select @a=c.name from syscolumns a,sysconstraints b,sysobjects 
    c where a.id=object_id('dbo.aqgj_dm')  and a.name='ab'
    and a.id=b.id and b.constid=c.id 
    and c.name like 'PK%'
    if @a is not null
    exec('alter table dbo.aqgj_dm drop constraint '+@a)
      

  9.   

    大力:我在查询分析器中执行语句:
    declare @a varchar(20)
    select * from syscolumns a,sysconstraints b,sysobjects c 
    where a.id=object_id('dbo.aqgj_dm')and a.id=b.id and b.constid=c.id
    and a.name='id'and c.name like 'PK%';
    if @a is not null
    exec('alter table dbo.aqgj_dm drop constraint '+@a)
    查出1条记录
    但主键并没有删除?
    我不知是什么原因,拜托!!!!!