1。。数据表有个字段叫id(数值型) ,,,我想通过一个语句将他变成主键。怎么写2. 数据表中有一字段叫aa,,如何删除他,,这语句怎么写3. 删除数据库的语句怎么写

解决方案 »

  1.   

    alter table tb add CONSTRAINT PK_Id primary key(id)alter table tb drop column aadrop database dbname
      

  2.   

    alter table tb add CONSTRAINT PK_Id primary key(id)alter table tb drop column aadrop database dbname
      

  3.   

    删除数据的语句Drop database 数据库名
      

  4.   


    if object_id('tb') is not null
       drop table tb
    go
    create table tb 
    (
     id int,
     name varchar(10)
    )
    go
    --设置主键
    --先设置列为非空,然后才能设置主键
    alter table tb alter column id int not null 
    go
    alter table tb add CONSTRAINT pk_tb_id PRIMARY KEY (id)
    --删除name列
    alter table tb drop column name
    --删除表
    drop table tb
      

  5.   

    针对第一条,最好alter table t1 alter column id int not null    --先设置为NOT NULL
    alter table t1 add constraint PK_T1 primary key (id)
      

  6.   

    alter table tb add CONSTRAINT PK_Id primary key(id)
    alter table tb drop column aa
    drop database dbname这都不会?自己找一本数据库书好好看看,这是最基本的了