如何修改表字段类型:--加
ALTER TABLE table2 ADD row_id bigint--删
ALTER TABLE table2 DROP COLUMN row_id--改
ALTER TABLE 你的表 ALTER COLUMN 列名 你的类型 null

解决方案 »

  1.   

    该类型已经定为主键,并且表中有数据: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%'if @a is not null
      exec('alter table 表名 drop constraint '+@a)
      

  2.   

    pengdali(大力 V3.0)的方法不行。
    会报错的。该类型已经定为主键,并且表中有数据。
      

  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%'
    if @a is not nullexec('alter table 表名 drop constraint '+@a)
    alter table 表名 add id1 intupdate 表名 set id1=主鍵列名alter table 表名 drop column 主鍵列名exec sp_rename '表名.id1','主鍵列名'alter table 表名 add constraint pk_表名_主鍵列名 primary key (主鍵列名)
      

  4.   


    declare @a varchar(200)
    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%'
    if @a is not nullexec('alter table 表名 drop constraint '+@a)
    alter table 表名 add id1 intupdate 表名 set id1=主鍵列名alter table 表名 drop column 主鍵列名exec sp_rename '表名.id1','主鍵列名'alter table 表名 add constraint pk_表名_主鍵列名 primary key (主鍵列名)
      

  5.   

    可以在企业管理器中去主键的属性去掉
    ALTER TABLE table2 ADD ALTER COLUMN column_name 
         new_data_type [ ( precision [ , scale ] 
    }
    ALTER TABLE table2 DROP COLUMN col_name
      

  6.   

    忘了not null--要将该字段的自动增加去掉。declare @a varchar(200)
    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%'if @a is not null
    exec('alter table 你的表 drop constraint '+@a)go
    alter table 你的表 add id1 int not null
    go
    update 你的表 set id1=你的列
    go
    alter table 你的表 drop column 你的列
    go
    exec sp_rename '你的表.id1','你的列'
    go
    alter table 你的表 add constraint pk_你的表_你的列 primary key (你的列)
      

  7.   

    ALTER TABLE 表 ADD 编号1 int 
    go
    update 表 set 编号1=编号
    go
    ALTER TABLE 表 DROP COLUMN 编号 
    go
    exec sp_rename '表.编号1','编号'
    go
      

  8.   

    1:可以在企业管理器中去主键的属性去掉
    ALTER TABLE table2 ADD ALTER COLUMN column_name 
         new_data_type [ ( precision [ , scale ] 
    }
    ALTER TABLE table2 DROP COLUMN col_name2:在企业管理器中修改.