今天要写一个产线信息,因为没有配置入口,需要先在程序里的主表上增加一条产线,然后再去程序里面在这条产线上增加三条明细线。我嫌麻烦,写了一个存储过程一并执行了。
-- 一、判断要创建的存储过程名是否存在,存在则删除 if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[insert_MY_SP_DictionaryClassByFactory]') and OBJECTPROPERTY(id, N'IsProcedure')= 1) drop procedure [dbo].[insert_MY_SP_DictionaryClassByFactory] go --二、创建插入主表的存储过程 create proc insert_MY_SP_DictionaryClassByFactory as begin declare @uncode varchar(100) select top 1 @uncode= dbo.ufn_GenerateUniqueID(22, floor(rand()*1e8)) insert into MY_SP_DictionaryClassByFactory ( FID,FFactoryCode,FClassCode,FClassName,FMaker,FMakeDate,FCheck,FCheckPeople,FCheckDate,pig_form_id ) values ( @uncode,'103','1176013','分割冻品外包线','200508650',GETDATE(),1,'200508650',GETDATE(),'103' ) --创建执行子表的存储过程 insert into MY_SP_DictionaryByFactory (FID,FInterID,FFactoryCode,FWorkshopCode,FCode,FName,FMaker,FMakeDate,FDelete,FCheck,FCheckPeople,FCheckDate,pig_form_id ) values (dbo.ufn_GenerateUniqueID(22, floor(rand()*1e8)),@uncode,'103','NX01-FG-WBZJ','1176013001','硬包1#线','200508650',GETDATE(),0,1,'200508650',GETDATE(),'103'), (dbo.ufn_GenerateUniqueID(22, floor(rand()*1e8)),@uncode,'103','NX01-FG-WBZJ','1176013002','硬包2#线','200508650',GETDATE(),0,1,'200508650',GETDATE(),'103'), (dbo.ufn_GenerateUniqueID(22, floor(rand()*1e8)),@uncode,'103','NX01-FG-WBZJ','1176013003','硬包3#线','200508650',GETDATE(),0,1,'200508650',GETDATE(),'103') end go --三、执行存储过程 exec insert_MY_SP_DictionaryClassByFactory --四、执行完删除存储过程 drop proc insert_MY_SP_DictionaryClassByFactory