資料庫MySQL 修改資料表

2022-07-20 08:33:06 字數 829 閱讀 8879

建立資料庫::create database 資料庫名;

如果資料不存在則建立,存在不建立:create database if not exists 資料庫名 ;

刪除資料庫::drop database 資料庫名;

修改資料表::關鍵字alter

修改資料表名:

:alter table 資料表名 rename to 新錶名;

刪除資料表中i欄位(關鍵字:drop):

:alter table 資料表名 drop i;

向資料表新增k 字段,並定義型別(關鍵字:add):

:alter table 資料表名 add k int;

向資料表新增k 欄位到指定欄位名後,並定義型別(關鍵字:after):

:alter table 資料表名 add k int after m; 

# 設定為第一列 關鍵字為first

修改資料表欄位名的資料型別(關鍵字:modify):

:alter table 資料表名 modify 欄位名 新資料型別;

修改資料表欄位名:(關鍵字:change):

## 關鍵字後緊跟這是要修改的欄位名,其後是指定的新名字及新型別 ##

:alter table 資料表名 change 就名字 新名字 字段型別;

修改資料表欄位名時,設定字段預設值(關鍵字:not null default):

:alter table 資料表名 modify 欄位名 資料型別 not null default 預設值;

修改字段預設值:

:alter table 資料表名 alter 欄位名 set default 新預設值;

MySQL 修改資料表

修改資料表是指修改資料庫中已有資料表的結構。mysql 使用 alter table 語句修改表。mysql 通過 alter table 語句修改表名,語法規則如下 alter table 舊表名 rename to 新錶名 其中 to 為可選引數,使用與否均不影響結果。修改欄位的資料型別,就是把...

MySQL修改資料表

alter ignore table tb name alter spec,alter spec.alter specification add column create definition first after column name 新增新字段 add index index name i...

MySql資料庫的基本操作 修改資料表

1.修改列定義 如改型別,改位置 alter table tbl name modify column col name column definition first after col name users2這張表的結構 可以看到,id 位於第三列,並未位於第 1列。這顯然不太合理。改位置 al...