如何将自动无格式设置为0001?在ms sql server 2005中 [英] How can I set auto increament format to 0001 ? in ms sql server 2005

查看:193
本文介绍了如何将自动无格式设置为0001?在ms sql server 2005中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将自动无格式设置为0001?在ms sql server 2005中

How can I set auto increament format to 0001 ?? in ms sql server 2005

推荐答案

您可以在表上插入触发器.此触发器可能包含为您生成自定义主键的逻辑.
但是,不能通过将auto-increment设置为true来直接生成这种密钥.
You could insert a trigger on the table. This trigger could contain logic to generate custom primary keys for you.
This kind of key cannot, however, be generated directly by setting auto-increment to true.


您好,请尝试

hi try this

CREATE TABLE tablename(
  id int(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (id)
);



它将添加
0001
0002 .... etc

希望它能奏效
如果可行,请接受答案.



it will add
0001
0002....etc

hope it works
accept answer if it works..


您不能-自动增量是整数

而且,您真的不想...让SP或客户端代码负责以所需的方式格式化数字

那只允许在您的ID开始换行之前在数据库中存储9999行
you can''t - the auto increment is an integer

and, you really don''t want to ... make it the responsibility of the SP or client code to format the number the way you want

That only allows your 9999 rows in your DB before your id''s start to wrap though


这篇关于如何将自动无格式设置为0001?在ms sql server 2005中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆