A(id,name,sex,age) 表在建立的时候没有指定主键,现在在程序中要将id设为主键,怎样写sql语句呢?
  alter.....  谢谢!

解决方案 »

  1.   

    没有人知道?  自己顶!(上面的表在sql_server中)
      

  2.   

    给你个例子:alter table student
    drop constraint pk_student  
    --去掉这个表的主键alter table student 
    add constraint pk_student primary key clustered (studentid, seq)
    --重新设置表的主键
      

  3.   

    ALTER TABLE distributors ADD PRIMARY KEY (dist_id)dist_id为新增字段。
      

  4.   

    alter table table1 alter column id int not nullALTER TABLE [dbo].[table1] WITH NOCHECK ADD 
    CONSTRAINT [PK_table1] PRIMARY KEY  CLUSTERED 
    (
    [id]
    )  ON [PRIMARY] 
      

  5.   

    to merkey2002(小样的) :    alter table student  drop constraint pk_student  
        --去掉这个表的主键   这个语句不能实现删除主键,出错提示:      Server: Msg 3728, Level 16, State 1, Line 1
         ‘pk_student‘ is not a constraint.
        Server: Msg 3727, Level 16, State 1, Line 1
        Could not drop constraint. See previous errors.