如何从MySQL表中删除现有列?
我们可以使用DROP语句和ALTER语句从MySQL表中删除特定的现有列。它的语法如下-
语法
ALTER TABLE table_name DROP column_name;
在这里, table_name是我们要从中删除列的表的名称。
Column_name是要从表中删除的列的名称。
示例
在此示例中,我们从表“student_detail”中删除“地址”列,如下所示:
mysql> select * from student_detail; +-----------+-------------+----------+ | Studentid | StudentName | address | +-----------+-------------+----------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | | 104 | Ram | Ludhiana | | 105 | Mohan | Patiala | +-----------+-------------+----------+ 5 rows in set (0.19 sec) mysql> ALTER TABLE student_detail DROP address; Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from student_detail; +-----------+-------------+ | Studentid | StudentName | +-----------+-------------+ | 100 | Gaurav | | 101 | Raman | | 103 | Rahul | | 104 | Ram | | 105 | Mohan | +-----------+-------------+ 5 rows in set (0.00 sec)
上面的结果集显示表中的“地址”列已被删除。
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短