mysql> Desc `user`;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  |      | PRI | 0       |       |
| name  | char(10) |      |     |         |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)mysql> ALTER TABLE `user` ADD UNIQUE `name` (`name`);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> Desc `user`;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  |      | PRI | 0       |       |
| name  | char(10) |      | UNI |         |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)mysql> ALTER TABLE `user` DROP INDEX `name`;
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> Desc `user`;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  |      | PRI | 0       |       |
| name  | char(10) |      |     |         |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)

解决方案 »

  1.   

    mysql> alter table p_program drop index tno;
    ERROR 1025: Error on rename of './paytv/#sql-488c_dc8' to './paytv/p_program' (e
    rrno: 150)
      

  2.   

    什么版本的 MySQL 你的表是 InnoDB 表??
    外键引用了 tno ??
      

  3.   

    create table p_program(
            prog_no         int not null auto_increment,
            prov_no         int not null,
            prog_id         varchar(20),
            prog_name       varchar(100) not null,
            chi_prog_name   varchar(100),
            duration        varchar(10) not null,
            category        varchar(2),
            start_date      datetime,
            end_date        datetime,
            prog_log_date   datetime,
            tno             int,
            total_run_per_mth       int(5),
            photo_image     varchar(100),
            cast            varchar(100),
            description     varchar(200),
            index p_program_idx02 (prov_no),
            foreign key (prov_no) references p_provider( prov_no ),
            index p_program_idx03 (tno),
            foreign key (tno) references p_program_type( tno ),
            primary key(prog_no),
            unique p_program_idx01 (prog_id)
    ) TYPE=INNODB;我最后用了drop table再重建才行,用的是innodb,tno是foregin key
    但我想知道有法子不?
      

  4.   

    但alter语句只有drop primary key,没drop foreign key请问是如何删除外键