检查序列是否可以使用
(由于您的数据有限,我假设您将 SQL Server 作为您的 DBMS)
Create Table T (ColABCIncremtnt varchar(20), Col2 int, Col3 datetime)
CREATE SEQUENCE dbo.Id AS INT
START WITH 1 INCREMENT BY 1 MINVALUE 0 NO MAXVALUE
Insert Into T (ColABCIncremtnt,Col2,Col3)
Select 'ABC000' + Convert(varchar(10), next value for dbo.Id), 43,getdate()
Insert Into T (ColABCIncremtnt,Col2,Col3)
Select 'ABC000' + Convert(varchar(10), next value for dbo.Id), 72,getdate()
Insert Into T (ColABCIncremtnt,Col2,Col3)
Select 'ABC000' + Convert(varchar(10), next value for dbo.Id), 36,getdate()
Select * from T
如果你想将序列嵌入到表格中
ALTER TABLE dbo.T
ADD CONSTRAINT Cnstrnt_Seq
DEFAULT FORMAT((NEXT VALUE FOR dbo.ID),'ABC000#') FOR ColABCIncremtnt;
Insert Into T (Col2,Col3) values
(1,getdate()),
(2,getdate()),
(3,getdate())
Select * from T