mysql表的主键、外键、限定、约定、索引、视同、存储过程

来源:互联网 发布:three.js obj模型 编辑:程序博客网 时间:2024/05/07 15:19

1、mysql表主键的设定:

如:

CREATE TABLE `system_dictionary_type` (
  `dictionary_type` varchar(32) NOT NULL COMMENT '字典类型',
  `dictionary_type_desc` varchar(50) DEFAULT NULL COMMENT '字典描述',
  `dictionary_type_status` int(22) DEFAULT NULL COMMENT '是否停用:0-启用;1-停用',
  PRIMARY KEY (`dictionary_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统数据字典类型表';

说明:该表主键为dictionary_type,primary key 为主键标示符。


2、UNIQUE约束(唯一约束)

如:

CREATE TABLE `system_dictionary` (
  `id` int(32) NOT NULL COMMENT '主键id',
  `dictionary_type` varchar(32) NOT NULL COMMENT '字典类型',
  `dictionary_code` varchar(32) NOT NULL COMMENT '字典值',
  `dictionary_parent_code` varchar(32) DEFAULT NULL COMMENT '父字典值',
  `dictionary_code_name` varchar(64) DEFAULT NULL COMMENT '字典名称',
  `dictionary_code_order` int(22) DEFAULT NULL COMMENT '显示的顺序',
  `dictionary_code_status` int(22) DEFAULT NULL COMMENT '是否停用:0-启用;1-停用',
  PRIMARY KEY (`id`),
  UNIQUE KEY `UNI_KEY` (`dictionary_code`,`dictionary_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统数据字典表(页面暂不提供维护功能,作为初始化数据导入,可实现多级字典)';

说明:由dictionary_code和dictionary_type字段共同构成唯一约束条件。


原创粉丝点击