MYSQL資料庫基礎之如果給已有資料庫表修改字段

2021-10-05 04:27:13 字數 912 閱讀 7346

mysql資料庫是當下程式開發的主流資料庫,在原生程式的過程中當資料庫建立的資料庫表不能滿足實際開發需求,需要對已有的資料庫表裡面的字段進行修改操作,這裡就不過多的進行詳細說明,只是對相關資料表字段調整的sql語句進行乙個歸納整理

修改欄位名稱

alter

table 表名 change 原表名 新錶名 varchar(32

)not

新增字段

alter

table

members

add 新增字段以及長度要求

新增多個欄位alter

table

members

add (新增字段以及長度要求)

為某一欄位設定預設值

alter

table 表名 alter 字段 set

default 預設值

alter

table 表名 alter 字段 drop

default 預設值

刪除字段

alter

table 表名 drop 刪除欄位名

修改字段資料型別

alter

table 表名 modify 字段 字段型別

修改欄位名稱以及資料型別

alter

table 表名 change 就名字 新名字 字段型別

新增主鍵約束

alter

table 表名 add

primary

key(字段)

新增唯一約束

alter

table 表名 add

unique

key(字段)

修改表名

alter

table 老名字 rename

to 新名字

MySql資料庫之資料庫基礎命令

繼續上篇部落格所說到的,使用命令玩轉mysql資料庫。在連線資料庫時,我們需要確定資料庫所在的伺服器ip,使用者名稱以及密碼。當然,我們一般練習都會使用本地資料庫,那麼本地資料庫的連線命令如下 mysql uroot p當我們成功連線資料庫後,先檢視一下當前都有什麼資料庫 show database...

資料庫之MySQL基礎(二)

1.基礎操作 建立資料庫 create database if notexists school 刪除資料庫 drop database if exists school 使用資料庫 tab 鍵的上面,如果你的表名或者欄位名是乙個特殊字元,就需要帶 use school 檢視資料庫 show dat...

資料庫 mysql 基礎

1.建立 create database 資料庫名 例如建立名為d testdb的資料庫 mysql create database d testdb 2.修改 alter database 資料庫名 character set 字符集名 例如修改字符集 set utf8 3.刪除 drop dat...