ORACLE数据库中如何插入一个唯一的主键


数据库中主键是唯一约束条件。同时可以设定不为空。

  今天项目中碰到问题,就是往数据库中插入数据,但是没有设定主键值;这样就必须自己去做判断,主键要唯一。

  自己给定一个方法去执行,就是用当前的时间去判断,获取小时甚至分秒都可以;这样主键肯定是唯一的了。

  方法:

  代码

  function getOid(){

  var today = new Date();//申明一个时间对象

  intDate = today.getDate();//返回当前的天日期

  intHours = today.getHours;//返回当前小时

  intMinutes = today.getMinutes();//分钟

  intSeconds = today.getSeconds();//秒

  intMonth = today.getMonth()+1 ;//月加1

  intYear = today.getYear();//返回年

  return intDate+""+intHours+""+intMinutes+""+intSeconds+""+intMonth+""+intYear;

  }

  这样就保证插入数据的时候主键是唯一的!


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3