Character biography as an ID

xiaoxiao2021-04-04  296

- Establish function crete function f_getbookid () Returns varchar (10) asbegindeclare @s varchar (10) SELECT @ s = 'bk' Right (10000000 ISNULL (Right (Max (Bookid), 8), 0) 1, 8) From BOOKReturn @S EndGO-- test environment CREATE TABLE BOOK (BookID varchar (10) NOT NULL Default dbo.F_GetBookID (), BookName varchar (20) NOT NULL, Constraint PK_BOOK_ID Primary key (BookID)) GO-- test Insert Book (BookName) Select 'Aa'Isert Book (Bookname) Select' B'Insert Book (Bookname) Select 'CC'

Select * from bookgo - Remove Test Environment DROP TABLE BOOKDROP FUNCTION F_GETBOOKID - Results / * BookidbookNameBK00000001AABK00000002BBBBK00000003CC * /

转载请注明原文地址:https://www.9cbs.com/read-131836.html

New Post(0)