alter table S 
drop constraint sno

alter table S 
drop constraint primary key(sno)上面语句都是错的,谁能给我一天正确的语句啊?

解决方案 »

  1.   

    EXEC sp_helpconstraint N'S' --自己查主键的名称.ALTER TABLE S
      DROP CONSTRAINT [PK_NAME]
    GO
      

  2.   

    先sp_help 表 查看这个表的主键约束名称,删除约束,再删除这列
      

  3.   


    第2个语法错误alter table S add constraint PK_S primary key(sno)--把drop改为add
      

  4.   

    select Name from sysobjects where xtyp='PK' and parent_obj=object_id('S')-- 查主健名
      

  5.   

    用系统存储过程查看先,然后决定删除哪个.例句如下:
    EXEC sp_helpconstraint '数据库名.所有者名.表名' 
    ---例 EXEC sp_helpconstraint 'employees.dbo.worker'ALTER TABLE S
      DROP CONSTRAINT [约束名(这里可以是任何约束,不单单是主键约束.)]
    GO
      

  6.   

    select Name from sysobjects where xtyp='PK' and parent_obj=object_id('S')-- 查主健名 
    HEHE ,这个直接,容易懂!可以查到主键名
      

  7.   

    select Name from sysobjects where xtyp='PK' and parent_obj=object_id('S')-- 查主健名 
    alter table S add constraint PK_S primary key(sno)--把drop改为add
    这样就可以了嘛,学习一下~
      

  8.   

    alter table S drop constraints pk_S;