您好,以下是常见操作范例供参考:
1. 添加列:alter table students add address char(60);
alter table students add birthday date after age;
2.修改列名,使用change需加上数据类型:
alter table students change tel telphone char(13) default “-”;
alter table students change name nm char(16) not null;
3. 修改数据类型,使用alter:
alter table students alter name char(10);
4. 删除列:
alter table students drop birthday;
5. 重命名表:
alter table students rename workmates;
6. 清除表格数据:
truncate table students;
7. 删除整张表:
drop table workmates;
8. 删除整个数据库:
drop database samp_db;
给表添加字段
mysql> alter table books add column id int ;
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。