--修改数据表SYS_Company中字段CompanyId自定义自增约束
ALTER TABLE [dbo].[SYS_Company]
Add Constraint DF_SYS_Company_CompanyId
DEFAULT ([dbo].[f_PrimaryCode_SYS_Company]()) FOR [CompanyId]
--Go
--删除约束
Alter table SYS_LogInfo Drop Constraint DF_SYS_Company_CompanyId
--创建数据表SYS_Company中字段CompanyId自定义自增约束(形如:CY00000001,长度为位,前两位为自定义编号,后位为流水号)
Create function [dbo].[f_PrimaryCode_SYS_Company]()
Returns Char(10)
As
Begin
RETURN(SELECT 'CY'+RIGHT(100000001+ISNULL(RIGHT(MAX(CompanyId),8),0),8) FROM SYS_Company WITH(XLOCK,PAGLOCK))
End