MySQL数据库访问(创建、修改、删除表)2018-06-19

2018-06-20  本文已影响0人  hothome99

--create table student;  创建了一个名为student 表;

数据表中数据三大类型:数字、字符串、日期;

--int float double tinyInt smallInt bigInt

int(10)指的是10位的整数;

float(5,2)指的是一共5位,其中2位是小数;

--char,varchar

char(5): 'ab' 从char(5)里取出来的就是3个空格加上ab;

varchar(5) :'ab'从varchar(5)里取出来的就是'ab';

--date datetime;

--create table student(  id varchar(5) primary key,name varchar(10) not null,birthday date,sex char(2) check(sex in('男','女')),goal int check(goal>=0 and goal<=100)  );

--descrirbe student;  描述显示表talbe 的结构;

添加一个列:alert table student add teacher varchar(10);

删除一个列:alert table student drop teacher;

修改一个列的数据类型:alert table student modify teacher varchar(20);

修改一个列的约束:alert table student modify teacher varchar(20) not null;

修改一个列的名字:alert table student change teacher t1 varchar(20);

上一篇 下一篇

猜你喜欢

热点阅读