MySQL指令基本分為三類:DDL(資料定義語言)、DML(資料操縱語言)、DCL(資料控制語言),
DDL:DDL指令的功能就是定義資料庫DATabase、表table、索引index、視圖view、列column等,DDL與DML的區別就在與DDL是對表進行定義、對結構進行修改,DML只能處理資料庫中的資料,不能對表結構進行更改,關鍵字有:insert、delete、update、SELECT、drop等,常用DDL語言包括以下:
create database db_name; //定義資料庫
create table tb_name( //定義表
id int(5), //定義列
name varchar(10)
);

create view view_name as select id fROMtb_name; //定義視圖
如果你在學習C/C++的程序中遇到了問題,可以來加入小編的企鵝圈問小編哦~小編很熱情的(●’?’●)
alter table tb_name add columntexttext [first/after 已存在的列名 ]; //添加一個text列
later table tb_name change 舊列名 新列名 資料型別; //修改表的一個列的列名
alter table tb_name modify 列名 新資料型別; //修改某列的資料型別
alter table tb_name rename 新表名; //修改表的名字
alter table tb_name engine=innoDB/MyISAM... //修改表的存盤引擎
alter table tb_name add index idx_name on tb_name(id); //創建普通索引索引idx_name基于id列;
alter table add unique(name); //創建唯一索引name;
alter table add primary key(列名) //添加主鍵索引
alter table tb_name drop 列名 //洗掉表的某列
drop index index_name on tb_name; //洗掉表的某個索引
show index from tb_name; //查看表的索引
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/237523.html
標籤:MySQL
