create table Student
(
Sno  int identity(1,1)  not null  primary key,
Sname   nvarchar(12)  not null ,
Ssex  nvarchar(12)  not null ,
Sbirthday  datetime  not null ,
Sage  int  not null ,
Sdept  nvarchar(12)  not null 
)
GO
怎么删除主键 ?   求解答   谢谢!

解决方案 »

  1.   

    create table Student
    (
    Sno int identity(1,1) not null primary key,
    Sname nvarchar(12) not null ,
    Ssex nvarchar(12) not null ,
    Sbirthday datetime not null ,
    Sage int not null ,
    Sdept nvarchar(12) not null  
    )
    GODeclare @PKName VarCHar(100)
    Select @PKName=name From sysobjects Where parent_obj=object_id('Student')
    Exec('Alter Table Student Drop Constraint '+ @PKName)
    Select name From sysobjects Where parent_obj=object_id('Student') And xtype='PK'
      

  2.   

    图形界面操作方便简单
    非要用语句
    这样吧
    --1查出主键约束名
    select name
    from sys.objects
    where parent_object_id=object_id('student')
    go
    --2删除主键约束
    alter table student
    drop constraint PK__Student__33D979A2 -- 步骤1查出的约束名
    go
    --3删除列
    alter table student
    drop column sno
      

  3.   

    alter table student drop column sno int
      

  4.   

    ---先先删除主键约束
    alter table student
    drop constraint 主键约束名
    ---然后删除主键列
    alter table student
    drop column sno int
      

  5.   

    alter table student
    drop constraint 主键约束名
    alter table student
    drop column sno int