1. 程式人生 > 其它 >如何建立mysql資料表入門

如何建立mysql資料表入門

技術標籤: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浮點