刚才写错了,用BEFORE INSERT触发器。在插入新数据前修改id为随机数,当然还有很多方法,比如在PHP代码里面实现。create trigger tr_id before insert on tablename for each row begin set new.id = round(rand()*10000000); end;
回复4楼: 还记得这段代码吗?你帮我解决的这个问题。 $sql="select concat(id,time) as id from student";//你的数据库中有数据不? 最好写成这样,方便你以后分割使用它。 $sql="select concat(id,'-',time) as id from student"; 现在想再增加一个随机数类型的字段 ,连接到一起确定一条记录。
先在你数据库表中增加一个字段sjid$num=rand();//任意整数要想设定范围:$num=rand(1,10);这是1~10的整数 $sql="select sjid from student where sjid='$num'"; $rs=mysql_query($sql,$conn); $rw=mysql_fetch_row($rs); $judge=trim($rw[0]);//去空格或null if(!empty($judge)){ echo "随机数以存在!"; }else{ $insert="insert into values('','$num')"; mysql_query($insert,$con); echo "插入成功!"; }
before insert on tablename
for each row
begin
set new.id = round(rand()*10000000);
end;
还记得这段代码吗?你帮我解决的这个问题。
$sql="select concat(id,time) as id from student";//你的数据库中有数据不?
最好写成这样,方便你以后分割使用它。
$sql="select concat(id,'-',time) as id from student"; 现在想再增加一个随机数类型的字段 ,连接到一起确定一条记录。
$sql="select sjid from student where sjid='$num'";
$rs=mysql_query($sql,$conn);
$rw=mysql_fetch_row($rs);
$judge=trim($rw[0]);//去空格或null
if(!empty($judge)){
echo "随机数以存在!";
}else{
$insert="insert into values('','$num')";
mysql_query($insert,$con);
echo "插入成功!";
}
能具体说一下怎么用吗?
比如,在学生表中增加一条学生时,怎样使用uuid()函数?
学生表:学号 姓名 性别 年龄
能详细说一下用法吗?