关闭

关于mySql中的自动增长值的设置

1575人阅读 评论(0) 收藏 举报
分类:

假设这次的建表语句中暂定企业表


-- -----------------------------------------------------
-- Table `FACTORY_INFO`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `FACTORY_INFO` ;

SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `FACTORY_INFO` (
  `FACTORY_ID` BIGINT NOT NULL AUTO_INCREMENT COMMENT '企业ID',  //这次是自增长值
  `FACTORY_LOGIN_ACCOUNT` VARCHAR(100) NOT NULL COMMENT '登陆账号',
  `FACTORY_LOGIN_PASSWORD` VARCHAR(40) NOT NULL COMMENT '登陆密码',
  `FACTORY_NAME` VARCHAR(100) NULL COMMENT '企业名称',
  `FACTORY_NAME_SHORT` VARCHAR(100) NULL COMMENT '企业简称',
  `FACTORY_LOGO` INT(11) NULL COMMENT '企业图片',
  `FACTORY_TYPE` INT(11) NULL COMMENT '企业类型',
  `FACTORY_LINKMAN` VARCHAR(20) NULL COMMENT '企业联系人',
  `FACTORY_INTRODUCE` VARCHAR(500) NULL COMMENT '企业介绍',
  `FACTORY_INTRODUCE_IMG1` INT(11) NULL COMMENT '企业介绍图1',
  `FACTORY_INTRODUCE_IMG2` INT(11) NULL COMMENT '企业介绍图2',
  `FACTORY_INTRODUCE_IMG3` INT(11) NULL COMMENT '企业介绍图3',
  `LINKMAN_TELPHONE` VARCHAR(20) NULL COMMENT '联系人电话',
  `LINKMAN_MAIL` VARCHAR(100) NULL COMMENT '联系人邮箱',
  `HOMEPAGE` VARCHAR(100) NULL COMMENT '企业官网',
  `ADDRESS` VARCHAR(200) NULL COMMENT '企业地址',
  `STATUS` CHAR(1) NOT NULL COMMENT '状态	0:未认证\n1:已认证\n',
  `BALANCE` DECIMAL(10,2) NOT NULL DEFAULT 0 COMMENT '账户余额',
  `PROVINCE` INT(4) NULL COMMENT '省',
  `CITY` INT(4) NULL COMMENT '市',
  `AREA` INT(4) NULL COMMENT '区',
  `IMAGE_IDENTIFICATION` INT(11) NULL COMMENT '企业上传证件',
  `CREATE_TIME` DATETIME NOT NULL COMMENT '创建时间',
  `CREATE_USER` VARCHAR(40) NOT NULL COMMENT '创建人',
  `UPDATE_TIME` DATETIME NOT NULL COMMENT '最后更新时间',
  `UPDATE_USER` VARCHAR(40) NOT NULL COMMENT '最后更新人',
  `DEL_FLG` INT(1) NOT NULL DEFAULT 0 COMMENT '删除FLG',
  PRIMARY KEY (`FACTORY_ID`)  COMMENT '')
ENGINE = InnoDB;


其中自增长的初始值设置:alter table factory_info AUTO_INCREMENT=4


XML中语句:


<insert id="insert" parameterType="model.factory.base.FactoryFactoryInfo" useGeneratedKeys="true" keyProperty="factoryId"
  >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Nov 03 10:41:28 CST 2015.
    -->
    insert into factory_info (FACTORY_ID, FACTORY_NAME, FACTORY_NAME_SHORT, 
      FACTORY_LOGO, FACTORY_TYPE, FACTORY_LINKMAN, 
      FACTORY_INTRODUCE, FACTORY_INTRODUCE_IMG1, 
      FACTORY_INTRODUCE_IMG2, FACTORY_INTRODUCE_IMG3, 
      LINKMAN_TELPHONE, LINKMAN_MAIL, HOMEPAGE, 
      ADDRESS, STATUS, BALANCE, PROVINCE,CITY,AREA,
      IMAGE_IDENTIFICATION, CREATE_TIME, CREATE_USER, 
      UPDATE_TIME, UPDATE_USER, DEL_FLG,FACTORY_LOGIN_PASSWORD,FACTORY_LOGIN_ACCOUNT
      )
    values (#{factoryId,jdbcType=BIGINT},#{factoryName,jdbcType=VARCHAR}, #{factoryNameShort,jdbcType=VARCHAR}, 
      #{factoryLogo,jdbcType=INTEGER}, #{factoryType,jdbcType=INTEGER}, #{factoryLinkman,jdbcType=VARCHAR}, 
      #{factoryIntroduce,jdbcType=VARCHAR}, #{factoryIntroduceImg1,jdbcType=INTEGER}, 
      #{factoryIntroduceImg2,jdbcType=INTEGER}, #{factoryIntroduceImg3,jdbcType=INTEGER}, 
      #{linkmanTelphone,jdbcType=VARCHAR}, #{linkmanMail,jdbcType=VARCHAR}, #{homepage,jdbcType=VARCHAR}, 
      #{address,jdbcType=VARCHAR}, #{status,jdbcType=CHAR}, #{balance,jdbcType=DECIMAL}, #{province,jdbcType=INTEGER},#{city,jdbcType=INTEGER},#{area,jdbcType=INTEGER},
      #{imageIdentification,jdbcType=INTEGER}, NOW(), #{createUser,jdbcType=VARCHAR}, 
      NOW(), #{updateUser,jdbcType=VARCHAR}, #{delFlg,jdbcType=INTEGER},#{factoryLoginPassword,jdbcType=VARCHAR},#{factoryLoginAccount,jdbcType=VARCHAR}
      )
  </insert>


就这样可以再插入的时候factoryId自己增长了~


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:17357次
    • 积分:404
    • 等级:
    • 排名:千里之外
    • 原创:23篇
    • 转载:6篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档