Alter table: drop primary and foreign key
/*
mysql> Drop table Books;
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE Books
-> (
-> ID SMALLINT NOT NULL,
-> Name VARCHAR(40) NOT NULL,
-> PubID SMALLINT NOT NULL DEFAULT 'Unknown'
-> )
-> ENGINE=INNODB;
Query OK, 0 rows affected (0.17 sec)
mysql> Describe Books;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID | smallint(6) | | | 0 | |
| Name | varchar(40) | | | | |
| PubID | smallint(6) | | | 0 | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> ALTER TABLE Books
-> DROP PRIMARY KEY,
-> DROP FOREIGN KEY fk_1,
-> DROP COLUMN Format;
ERROR 1091 (42000): Can't DROP 'PRIMARY'; check that column/key exists
mysql> Describe Books;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID | smallint(6) | | | 0 | |
| Name | varchar(40) | | | | |
| PubID | smallint(6) | | | 0 | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
*/
Drop table Books;
CREATE TABLE Books
(
ID SMALLINT NOT NULL,
Name VARCHAR(40) NOT NULL,
PubID SMALLINT NOT NULL DEFAULT 'Unknown'
)
ENGINE=INNODB;
Describe Books;
ALTER TABLE Books
DROP PRIMARY KEY,
DROP FOREIGN KEY fk_1,
DROP COLUMN Format;
Describe Books;
Related examples in the same category