建立後表的修改:添加列+修改列+刪除列+重命名錶+刪除整張表+刪除整個數據庫

建立後表的修改

alter table 語句用於建立後對錶的修改, 基礎用法以下:數據庫

添加列

基本形式: alter table 表名 add 列名 列數據類型 [after 插入位置];table

示例:基礎

在表的最後追加列 address: alter table students add address char(60);date

在名爲 age 的列後插入列 birthday: alter table students add birthday date after age;數據類型

修改列

基本形式: alter table 表名 change 列名稱 列新名稱 新數據類型;命名

示例:數據

將表 tel 列更名爲 telphone: alter table students change tel telphone char(13) default "-";db

將 name 列的數據類型改成 char(16): alter table students change name name char(16) not null;tab

刪除列

基本形式: alter table 表名 drop 列名稱;di

示例:

刪除 birthday 列: alter table students drop birthday;

重命名錶

基本形式: alter table 表名 rename 新表名;

示例:

重命名 students 表爲 workmates: alter table students rename workmates;

刪除整張表

基本形式: drop table 表名;

示例: 刪除 workmates 表: drop table workmates;

刪除整個數據庫

基本形式: drop database 數據庫名;

示例: 刪除 samp_db 數據庫: drop database samp_db;

相關文章
相關標籤/搜索