mysql更新表結構 mysql更新資料表結構命令

2021-10-17 15:28:52 字數 890 閱讀 3880

mysql中alter命令的用法,用於編輯表結構

修改表名alter table test rename test1;

修改字段型別alter table employee change depno depno int(5) not null;

加索引alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);

例子:alter table employee add index emp_name (name);

加主關鍵字的索引alter table 表名 add primary key (欄位名);

例子:alter table employee add primary key(id);

加唯一限制條件的索引alter table 表名 add unique 索引名 (欄位名);

例子:alter table employee add unique emp_name2(cardnumber);

檢視某個表的索引show index from 表名;

例子:show index from employee;

刪除某個索引alter table 表名 drop index 索引名;

例子:alter table employee drop index emp_name;

增加表字段:alter table table_name add field_name field_type;

檢視表:select * from table_name;

修改原欄位名稱及型別:alter table table_name change old_field_name new_field_name field_type;

刪除字段:alter table table_name drop field_name;

mysql臨時表更新 MySql 臨時表

今天在專案中遇到乙個,當mysql的in語句中資料量很大時,建立乙個臨時表的例子。於是樓主整理了一下關於臨時表的知識,與大家分享一下 首先,臨時表只在當前連線可見,當關閉連線時,mysql會自動刪除表並釋放所有空間。因此在不同的連線中可以建立同名的臨時表,並且操作屬於本連線的臨時表。建立臨時表 cr...

MySQL筆記建立表結構 MySQL表結構筆記9

本篇大綱 mysql資料表 建立表建立主鍵 auto increate 指定預設值 更新表結構 刪除表,重新命名表 01 表 mysql 資料庫的表是乙個二維表,由乙個或多個資料列構成 每個資料列都有它的特定型別,該型別決定了mysql如何看待該列資料 02 建立表 命令 格式 使用create t...

mysql 更新 排名 更新MySQL表中的排名

一種選擇是使用排名變數,例如 update player join select p.playerid,currank currank 1 as rank from player p join select currank 0 r order by p.points desc ranks on ra...