MySQL 表結構操作

2021-09-17 04:52:07 字數 1040 閱讀 9916

不要忽略『』;『』

1:建立**:

create table **名(欄位名1 字段資料型別,欄位名2 字段資料型別,…)

例如:create table students(id int,name varchar(20),*** varchar(10),score float(4,1));

2:檢視**結構:

desc **名;

3:檢視**細節:

show create table **名;

區分 檢視資料庫建立細節(細節:比如字符集):show create database 資料庫名;

4:修改**操作:

(1)新增字段(列)----alter table 表名add欄位名 資料型別;

(2)修改欄位的資料型別----alter table 表名modify欄位名 新的資料型別;

(3)修改欄位名----alter table 表名 change 舊欄位名 新欄位名 新字段資料型別;

(4)刪除欄位----alter table 表名 drop 欄位名;

(5)修改**字符集----alter table 表名 character set 字符集;或者

alter table 表名 charset=字符集;

(6)修改表名----alter table 表名 rename to 新錶名;或者

rename table 舊表名 to 新錶名;

(7)刪除**----drop table 表名;

(8)mysql在特定位置增加表字段的命令:

alter table 表名 add 新欄位名 字段型別 after 原表中某個欄位名 ;

(9)為t_test已有表中的字段設定預設值:

alter table 表名 alter column 字段 set default 『預設值』;

利用after即可實現。

與刪除資料庫一起記憶:drop database;

總結:與**操作有關的大都有 alter +table 除了個別的

MySql 操作表結構

mysql 一些簡單對錶操作的語句 一 建立表 和 建立臨時表 建立表 create table table name column one int,column two varchar 20 建立臨時表 createtemporarytabletable name column one int,c...

MySQL修改表結構操作命令總結

這篇文章主要介紹了mysql修改表結構操作命令總結,包含如刪除列 新增列 修改列 新增主鍵 刪除主鍵 新增唯一索引 新增普通索引等內容,需要的朋友可以參考下 表的結構如下 複製 如下 mysql show create table person person create table person ...

表結構操作

1 複製表結構及資料到新錶 create table 新錶select from 舊表 這種方法會將oldtable中所有的內容都拷貝過來,當然我們可以用delete from newtable 來刪除。不過這種方法的乙個最不好的地方就是新錶中沒有了舊表的primary key extra auto...