如何在sql中创建自动生成的quatation数 [英] how to create a auto generated quatation number in sql

查看:85
本文介绍了如何在sql中创建自动生成的quatation数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql中创建自动生成的quatation数字



i在sql中创建了一个表,但是这个表如何生成一个quatation数,每次插入一个quatation号码创建



请帮助我任何人

how to create a auto generated quatation number in sql

i have created one table in sql but this table how to genrated a quatation number, each time insert one quatation number created

pls help me anybody

推荐答案

你可以使用身份表格中的列。



解释 [ ^ ]

< a href =https://msdn.microsoft.com/en-gb/library/ms186775.aspx>文档 [ ^ ]





主键无关紧要。



IDENTITY列自动生成数字。这些可能不是连续的,因为删除后值不变(与使用ROWNUMBER()之类的东西不同,其中数字将始终被再生)。



例如,创建一个样本表
You could use an Identity column in your table.

Explanation[^]
Documentation[^]


Primary key is irrelevant.

IDENTITY columns get automatically generated numbers. These may not be sequential as the values are unchanged after deletions (unlike using something like ROWNUMBER() where the numbers will always be regenenerated).

For example, create a sample table
create table CP2
(
	QuoteNo int IDENTITY(10001,1),
	SomeOtherData varchar(max)
)

insert into CP2 values
('item 1'),
('item 2'),
('item 3')

这将自动生成 QuoteNo 值:

10001	item 1
10002	item 2
10003	item 3

你想要你的特殊格式 - 所以在显示点格式化它们,例如

You want yours in a particular format - so format them at the point of display e.g.

SELECT 'QU-' + CAST(QuoteNo as varchar)
from CP2

QU-10001
QU-10002
QU-10003


根据OP对解决方案1的评论, CHill60 [ ^ ]



请参考:

[ ^ ]

如何在sql server 2008 r2中增加varchar [ ^ ]

在SQL Server中设置自定义自动生成/增量字段 [ ^ ]
As per OP's comment to the solution 1 by CHill60[^]

Please, refer this:
Create a custom auto-increment field in SQL Server[^]
how to increment varchar in sql server 2008 r2[^]
Set Custom auto generated/increment field in SQL Server [^]


你可以参考这个 [ ^ ]用于质量解决方案。
You can reference this[^] for a quality solution.


这篇关于如何在sql中创建自动生成的quatation数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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