--删约束的方法:alter table 表名 drop constraint PK__.....--删列
Alter Table 表名 Drop column 列名

解决方案 »

  1.   

    create table A
    (
      ID int primary key,
      num int
    )declare @constname varchar(50)
    select @constname=object_name(constid) 
    from sysconstraints 
    where id=object_id('A')--删除约束
    exec('alter table A drop constraint '+@constname)
    --删除列
    exec('alter table A drop column ID')--查看
    select * from A--删除册环境
    drop table A
    --结果
    /*
    num         
    ----------- (所影响的行数为 0 行)
    */
      

  2.   

    不行啊。
    我要删除person表的primary key.
    用如下的sql:
       alter table person drop constraint pk_person
    运行有错误,提示错误为:   'PK__person' 不是约束。为什么会这样。请高手指点
      

  3.   

    應該是你的約束名字寫錯啦,
    您先用vivianfdlpw()給出的方法找到約束名:
    declare @constname varchar(50)
    select @constname=object_name(constid) 
    from sysconstraints 
    where id=object_id('A')
    select @constname
    若:找到的是'PK_111'
    然後在執行
    alter table person drop constraint pk_111
      

  4.   

    /* 
       删除指定表的主键字段   调用: exec deletePK '表名','列名'*/
    alter procedure deletePK
    @tbName varchar(20),  --表名
    @colName varchar(20)  --列名
    asdeclare @constname varchar(50)
            ,@sql varchar(1000)
    select @constname=object_name(constid) 
    from sysconstraints 
    where id=object_id(quotename(@tbName))--删除约束
    set @sql='alter table '+quotename(@tbName)+' drop constraint '+@constname
    exec(@sql)
    --删除列
    set @sql='alter table '+quotename(@tbName)+' drop column '+quotename(@colName)
    exec(@sql)go
      

  5.   

    不行啊。
    我要删除person表的primary key.
    用如下的sql:
       alter table person drop constraint pk_person
    运行有错误,提示错误为:   'PK__person' 不是约束。为什么会这样。请高手指点'PK__person' 不是约束
    你可以先用sp_help person 查到约束名,然后再执行你上面的语句
      

  6.   

    先用
    exec sp_helpconstraint 'person'
    查看是否存在这个约束猜测:是不是建立的是一个索引,而不是约束?