论坛首页 入门讨论版 rails

在rails中怎么获取mysql中的sequence值。

浏览 944 次
该帖已经被评为新手帖
作者 正文
最后更新时间:2007-03-09 关键字: sequence
在rails中怎么获取mysql中的sequence值。
一般可以这样:
#

Create a table to hold the sequence counter and initialize it:

mysql> CREATE TABLE sequence (id INT NOT NULL);
mysql> INSERT INTO sequence VALUES (0);

#

Use the table to generate sequence numbers like this:

mysql> UPDATE sequence SET id=LAST_INSERT_ID(id+1);
mysql> SELECT LAST_INSERT_ID();


但是在 rails中的 update不能直接执行 sql语句,那该如何
   
论坛首页 入门讨论版 rails

跳转论坛:
JavaEye推荐