mysql学习2

--创建表

create table 表名字(

列名 列的类型(指定长度) 约束 ,列

名2 列2的类型 约束

);

列的类型:

int

char(固定长度) varchar(可变长度)    

double float boolean

date:YYYY-YY-YY

time:hh:hh:hh

datetime:YYYY-YY-YY hh:hh:hh 默认是null

timestamp:YYYY-YY-YY hh:hh:hh 默认是当前时间

text:主要是用来存放文本

blob:存放二进制

列的约束:

主键约束 :primary key 

唯一约束:unique

非空约束:not null

创建表:

1分析实体 :学生 

2学生ID 姓名 性别 年龄

create table student(

sid int primary key,

sname varchar(10),

sex int ,

age int 

);

--查看所有表

show tables;

 --查看表的定义

show create table student;

--查看表结构

desc student;

--修改表

添加列(add)

alter table 表名 add 列名 列的类型 列的约束

alter table student add chengji int not null;

--修改列(modify) 

alter table student modify sex varchar(2);

--修改列名(change)

alter table studen change sex gender varchar(2);

--删除列(drop)

alter table student drop chengji;

--修改表名(rename),修改表的字符集(一般不要用)

rename table student to xuesheng;

alter table student character set gbk;

--删除表

drop table student;

 

 

posted @ 2021-01-08 11:49  渊祭  阅读(45)  评论(0)    收藏  举报