发表于: 2017-11-30 23:43:11

2 713


首次以这种方式学习,发现确实有些不一样,带着问题学东西才能检验自己到底掌握了多少。

目前的进度为完成表格的设计工作,更具帖子中的描述,我认为需要三个对象:分别为学员、师兄、日报,相应的对应三张表:tab_student,tab_teacher,tab_daily。其中学员和日报为一对多的关系,学员和师兄为一对一的关系(暂时这么认为)。进一步我完成了如下的表格设计:

1、建表语句如下:

//师兄建表语句

create table tab_teacher(

t_id int primary key auto_increment,

t_name varchar(20),

create_at timestamp not null default current_timestamp,

update_at timestamp default current_timestamp on update current_timestamp

);

//学员建表语句

create table tab_student(

s_id int primary key auto_increment,

QQ int,

entrence_time datetime,

direction varchar(20),

graduate_student varchar(20),

information_source varchar(50),

teacher_id int,

create_at timestamp default current_timestamp,

update_at timestamp default current_timestamp on update current_timestamp,

foreign key (teacher_id) references tab_teacher(t_id)

);

//日报建表语句

create table tab_daily(

d_id int primary key auto_increment,

d_author int,

d_title varchar(20),

d_address varchar(100),

create_at timestamp not null default current_timestamp,

update_at timestamp default current_timestamp on update current_timestamp,

foreign key (d_author) references tab_student(s_id)

);


建成表格建构如下:

教师表:

学员表:


日报表:


主要的收获就是关于create 和 update 的两个时间戳的添加。

之前都完全不知道数据有这个功能,添加的语句如下:

update_at timestamp default current_timestamp on update current_timestamp,

红色部分表示,默认会填写操作该条记录时的时间,如果去掉红色部分的语句,这里不指定的话会显示全是0;

绿色部分表示在某条记录执行update操作的时候,这里会填入执行update的时间戳。

另外mysql的视图话工具用着不熟练,还需要慢慢摸索,明天继续往下走,明天争取完成大步骤15。



返回列表 返回列表
评论

    分享到