用户表和部门表的数据库设计

部门表

create table `sys_dept`(
	`id` int not null  auto_increment comment '部门id',
	`name` VARCHAR(20) not null DEFAULT '' comment '部门名称',
	`parent_id`  int  not null  DEFAULT 0  comment  '上级部门id' ,
	`level`  VARCHAR(200) not null DEFAULT '' comment '部门层级',
	`seq`  int  not null DEFAULT 0 comment '部门在当前层级下的顺序,由小到大',
	`remark` VARCHAR(200) DEFAULT '' comment '备注' ,
	`operator` VARCHAR(20) not null  DEFAULT '' COMMENT '操作者',
	`operator_time` datetime  not null DEFAULT CURRENT_TIMESTAMP ON UPDATE 
                                            CURRENT_TIMESTAMP   COMMENT '最后一次操作时间' ,
	`operator_ip` VARCHAR(20)  not null DEFAULT '' comment 	'最后一名操作者的ip' ,
	PRIMARY KEY (`id`)
) comment  '部门表';

用户表

CREATE TABLE `sys_user` (
  `id` int(32) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  `username` varchar(64) NOT NULL DEFAULT '' COMMENT '用户名字',
  `telephone` varchar(64) NOT NULL DEFAULT '' COMMENT '用户手机号',
  `mail` varchar(64) NOT NULL DEFAULT '' COMMENT '用户邮箱',
  `password` varchar(64) NOT NULL DEFAULT '' COMMENT '用户密码',
  `remark` varchar(255) DEFAULT '' COMMENT '备注',
  `dep_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户部门表',
  `status` tinyint(3) NOT NULL DEFAULT '1' COMMENT '用户的状态 1 :正常  0:冻结 2:删除',
  `operator` varchar(64) NOT NULL DEFAULT '' COMMENT '操作人',
  `operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '操作时间',
  `operator_ip` varchar(64) NOT NULL DEFAULT '' COMMENT '操作人的ip',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

 

 

说明:

1.为什么not null default 0 或者 not null default ''   https://blog.csdn.net/KingOfMyHeart/article/details/88893426

2.create_time 和 update_time  用的是 default current_timestamp on update current_timestamp

如果用的navicat创建表结构的话用的是now() 

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值