Om toe te voegen aan het RMathis-antwoord, kunt u alles binnen SQL doen door ook SET te gebruiken om de DROP-tekenreeks te definiëren in combinatie met VOORBEREIDEN en UITVOEREN
MySQL 5.6 Schema-instellingen :
CREATE TABLE Table1
(`col1` varchar(1),
`col2` varchar(1),
`col3` varchar(1),
`col4` varchar(1),
`col5` varchar(1))
;
set @col = (select column_name
from information_schema.columns
where table_name='table1' and ordinal_position=3);
SET @s = CONCAT("alter table table1 drop column ", @col);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Query 1 :
desc table1
| COLUMN_NAME | COLUMN_TYPE | IS_NULLABLE | COLUMN_KEY | COLUMN_DEFAULT | EXTRA |
|-------------|-------------|-------------|------------|----------------|-------|
| col1 | varchar(1) | YES | | (null) | |
| col2 | varchar(1) | YES | | (null) | |
| col4 | varchar(1) | YES | | (null) | |
| col5 | varchar(1) | YES | | (null) | |