alter table test1 alter column ide int identity(1,1) not null
这样写为什么不对?应该怎么写,我的目的是把一个varchar列改为int并且自增

解决方案 »

  1.   

    修改数据库中字段的定义:
    ALTER TABLE table_neme  ALTER COLUMN  abc   varchar(100)  null;
                ^^^^^^^^^^               ^^^^^  ^^^^^^^^^^^^^^^^^^ 
                 表名                   字段名        字段属性
    ---------------
    例如:
    var ss:string;
    begin
     ss:='ALTER TABLE tab  ALTER COLUMN  a  varchar('+Edit1.Text+')';//根据Edit1.Text中的数字可以动态修改
    with ADOQuery1 do
     begin
       Close;
       SQL.Clear;
       SQL.Add(ss);
       ExecSQL;
     end;
    end;
      

  2.   

    难道我们delphi版的人气就这么差?????????????
      

  3.   

    ALTER COLUMNSpecifies that the given column is to be changed or altered. ALTER COLUMN is not allowed if the compatibility level is 65 or earlier. For more information, see sp_dbcmptlevel. The altered column cannot be: A column with a text, image, ntext, or timestamp data type.
    The ROWGUIDCOL for the table.
    A computed column or used in a computed column.
    A replicated column.
    Used in an index, unless the column is a varchar, nvarchar, or varbinary data type, the data type is not changed, and the new size is equal to or larger than the old size.
    Used in statistics generated by the CREATE STATISTICS statement. First remove the statistics using the DROP STATISTICS statement. Statistics automatically generated by the query optimizer are automatically dropped by ALTER COLUMN.
    Used in a PRIMARY KEY or [FOREIGN KEY] REFERENCES constraint.
    Used in a CHECK or UNIQUE constraint, except that altering the length of a variable-length column used in a CHECK or UNIQUE constraint is allowed.
    Associated with a default, except that changing the length, precision, or scale of a column is allowed if the data type is not changed. 
    Some data type changes may result in a change in the data. For example, changing an nchar or nvarchar column to char or varchar can result in the conversion of extended characters. For more information, see CAST and CONVERT. Reducing the precision and scale of a column may result in data truncation.你这种情况完全可以用drop column /add column的方式
      

  4.   

    问题已经用其他方法解决了。
    TO:atyzy(笑闹江湖) 散分不能升级,但能促进升级。哈哈!
      

  5.   

    先 Drop 掉你的那个 varchar column, then add identity id column.