Alter table : Alter Table : Table Index SQL / MySQL


SQL / MySQL » Table Index » Alter Table »

 

Alter table



/*
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(40NOT 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;

           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

SQL / MySQL

 Navioo Table Index
» Alter Table