如何自动生成票号? [英] How to autogenerate ticket number?

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

问题描述

如何自动生成故障单号并保存到数据库中?

关于将帮助台故障单创建到任何项目中的问题。

How to autogenerate Ticket number and save into database?
This question regarding help desk ticket creation into any project.

推荐答案

In您的数据库架构设置了一列以使用 IDENTITY 属性

例如

In your database schema have one column set up to use the IDENTITY property
e.g.
create table myTable(
TicketID int not null IDENTITY(1,1)
-- other columns ...
)



这将自动创建一个从1开始的TicketID code>( 1 ,1)并且每次添加一行时递增1 (1, 1 的)。它将自动处理从表中删除的所有行,确保TicketID始终是唯一的。



请参阅此链接 [ ^ ]文档


This will automatically create a TicketID starting at 1 (1,1) and incrementing by 1 each time a row is added (1,1). It will automatically handle any rows that are deleted from the table ensuring that the TicketID is always unique.

See this link[^] for the documentation


让SQL Server为你工作。



1.在 INT 的Ticket表中声明主键列(TicketNumber)或 BIGINT 数据类型使用列属性标识规范 IsIdentity 设置为是,标识增量设置为1,标识种子设置为1.
Let SQL Server do the work for you.

1. Declare a Primary Key column (TicketNumber) in the "Ticket" table of INT or BIGINT Data Type with Column Properties Identity Specification IsIdentity set to Yes, Identity Increment set to 1 and Identity Seed set to 1.
CREATE TABLE YourTableName (
TicketNumber INT NOT NULL IDENTITY(1,1),

-- ...
-- The remainder of your table's columns go here
-- ...

)

CREATE TABLE YourTableName (
TicketNumber BIGINT NOT NULL IDENTITY(1,1),

-- ...
-- The remainder of your table's columns go here
-- ...

)

2。在新的Ticket行的 INSERT 之后,使用 SCOPE_IDENTITY 函数获取插入行的主键。该值是票号。



*参见检索身份或自动编号值(ADO.NET) [ ^ ]。

*请参阅检索 SCOPE_IDENTITY 的示例< a href =http://msdn.microsoft.com/en-us/library/vstudio/hdt3k85x.aspx>从数据库中获取单个值 [ ^ ]。

2. After an INSERT of a new "Ticket" row, use the SCOPE_IDENTITY function to get the Primary Key of the inserted row. That value is the "Ticket Number".

* See Retrieving Identity or Autonumber Values (ADO.NET)[^].
* See example of retrieving SCOPE_IDENTITY at Obtaining a Single Value from a Database[^].


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

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