<id name="SId" type="java.lang.Integer">
<column name="s_id" />
<generator class="native" />
</id>怎样让主键SID从2004182401开始自增?,每次增加1,效果是;2004182401 2004182402 2004182403 ......
默认时只能从1开始
用到的数据库是MySQL
<column name="s_id" />
<generator class="native" />
</id>怎样让主键SID从2004182401开始自增?,每次增加1,效果是;2004182401 2004182402 2004182403 ......
默认时只能从1开始
用到的数据库是MySQL
例如:create function f_max()
returns char(4)
as
begin
declare @s int
select @s = isnull(max( cast(id as int)),0) + 1 from ta
return right('0000'+ ltrim(@s),4)
end
go
create table ta(ID char(4) default (dbo.f_max()) primary key,col int)
goinsert ta(col) select 2
insert ta(col) select 3
select * from ta
/*
ID col
---- -----------
0001 2
0002 3(所影响的行数为 2 行)
*/
drop table ta
drop function f_max
你写的是一个存储函数吗?它的作用我有点看不懂,还请详细指教.
CREATE TABLE `test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2004182401 DEFAULT CHARSET=utf8;
INT 可能满足不了, 用BIGINT
我做项目的时候建表,就已经用了和你一样的方式,但把表反转(Hibernate Reverse Engineering)成实体类和映射文件后,就只能从1开始递增了