如何建立mysql資料表入門
阿新 • • 發佈:2020-12-24
技術標籤:mysql
表的基本操作
以下建一個學生表舉例子
表如圖:
建立一個學生表
create table if not exists student(
id int auto_increment primary key comment'學號',
name varchar(20),
sex enum('男','女'),
age int );
檢視如何建立資料表
show create table student;
查看錶結構
desc student;
修改表字符集
alter table student charset=utf8;
修改表名
alter table student rename to student;
修改表字段型別
alter table student modify sex varchar(20) character set utf8;
修改表字段順序
alter table student modify sex varchar(20) first; //or
alter table student modify sex varchar(20) after id;
新增表字段
alter table student add (class varchar(20),ld varchar(20));
修改表字段名
alter table student change sex xingbie varchar (20);
刪除表字段名
alter table student drop sex;
資料型別 | 型別說明 |
---|---|
char | 固定長度字串 |
varchar | 可變長度字串 |
text | 大文字資料 |
enum | 列舉型別(多選一,沒有不可以選) |
int | 數字 |
float | 浮點 |