創建存儲過程模板

create proc [dbo].[wp]
@tablename varchar(64)
as
set nocount on
set transaction isolation level read uncommitted
set xact_abort on
begin
–判斷表存不存在
declare @tableid int = object_id(@tablename)
if @tableid is null
begin
select @tablename + ‘table not exists’ as error
return
end
–生成模板
declare @table table(code varchar(256))
insert into @table(code)
select ‘-- =============================================’ union all
select '-- Author: wll ’ union all
select '-- Create date: ’ + CONVERT (nvarchar(19),GETDATE(),120) union all
select '-- Description: ’ union all
select ‘-- =============================================’ union all
select ‘create proc p_’ union all
select ‘as’ union all
select ‘set nocount on’ union all
select ‘set transaction isolation level read uncommitted’ union all
select ‘set xact_abort on’ union all
select ‘begin’ union all
select ‘end’ union all
select ‘go’
select code as temp from @table
end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章