我有一库存表,有一字段:编号,字段类型为smallint,我刚开始没设主键,我想在程序中用代码把编号设为主键,怎么设?

解决方案 »

  1.   

    sql.Clear;
      sql.add('alter table 表名 (');
      sql.add('Primary Key (编号))');//设为主键;
      Prepare;
      Execsql;
    没试过,不知道行不……
      

  2.   

    with ADOQuery do
    begin
      close;
      sql.clear;
      sql.text := 'alter table 表名 add CONSTRAINT PK_name primary key (字段)';
      try
        ExecSQL;
      except  end;
    end;
    但要保证该字段为非空(not null)
      

  3.   

    回复人: fhuibo(永远深爱一个叫“莎“的好女孩儿) ( ) 信誉:100 主键改好了,可还不是标识,我想同时改为标识,这样用户不用输入编号了,编号可自动生成.
      

  4.   

    alter table .....
    add.....
      

  5.   

    SQL Server,我想让标识自动加1