1--The followingCodeGenerate an 8-digit serial number. The serial number starts with BH and the remaining six digits are serial numbers. 2--Function with the new number 3CreateFunctionF_nextbh () 4ReturnsChar(8) 5As 6Begin 7Return(Select'BH'+ Right(1000001+Isnull(Right(Max(BH ),6),0),6)FromTBWith(Xlock, paglock )) 8End 9Go 10 11--Apply functions in the table 12CreateTableTB ( 13BHChar(8)PrimaryKeyDefaultDBO. f_nextbh (), 14ColInt) 15 16--Insert data 17BeginTran 18InsertTB (COL)Values(1) 19InsertTB (COL)Values(2) 20InsertTB (COL)Values(3) 21DeleteTBWhereCol=3 22InsertTB (COL)Values(4) 23InsertTB (BH, col)Values(DBO. f_nextbh (),14) 24CommitTran 25 26--Display result 27Select*FromTB 28/*-- Result 29BH col 30--------------------------- 31Bh120001 1 32Bh120002 2 33Bh120003 4 34Bh000004 14 35--*/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service