mysql生成带初始值的序列号

笑莫问 2010-04-27 05:30:15
eg:
create table user(
id int auto_increment primary key
);
这样生成的id是从1开始的,我想让它从10000开始递增,怎么写sql语句?
...全文
258 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
peenyking 2010-05-21
  • 打赏
  • 举报
回复
我也在找这个呢
笑莫问 2010-04-28
  • 打赏
  • 举报
回复
解决了:
可在建表时可用“AUTO_INCREMENT=n”选项来指定一个自增的初始值。

可用alter table table_name AUTO_INCREMENT=n命令来重设自增的起始值。
笑莫问 2010-04-27
  • 打赏
  • 举报
回复
是用mysql数据库吗?我的建表出错
mysql> create table tb
-> (
-> id int identity(10000,1) primary key,
-> col int
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL s
erver version for the right syntax to use near 'identity(10000,1) primary key,
col int
)' at line 3
挨踢直男 2010-04-27
  • 打赏
  • 举报
回复
if object_id('tb') is not null
drop table tb

create table tb
(
id int identity(10000,1) primary key,
col int
)

insert tb(col) select 1
union all
select 2

select * from tb


(2 行受影响)
id col
----------- -----------
10000 1
10001 2

(2 行受影响)

2,100

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧