如何在所有数据库中创建程序? [英] how to create procedure in all database?
本文介绍了如何在所有数据库中创建程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Iam执行以下查询但收到错误..
Iam executing below query but getting error..
execute master.sys.sp_MSforeachdb
use [?];
if exists
(
select * from sys.tables
)
create proc parentupdate
(
@fscode varchar(50),
@parent varchar(50)
)
as
begin
update Tbl_FS_Mst set C_Parent='@parent'
N_ptype=(select N_Type from Tbl_FS_Mst where C_Code='@parent') where
C_Code='@fscode'
end
错误是这样的..
消息156,等级15,状态1,行9
关键字'proc'附近的语法不正确。
消息156,等级15,状态1,行9
error is like this..
Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'proc'.
Msg 156, Level 15, State 1, Line 9
推荐答案
不确定但可能的解决方案是创建单独的批处理来执行不同的语句,例如
Not sure but a possible solution can be creating separate batches for executing different statements like
execute master.sys.sp_MSforeachdb
GO
use [?];
if exists
(
select * from sys.tables
)
GO
create proc parentupdate
(
@fscode varchar(50),
@parent varchar(50)
)
as
begin
update Tbl_FS_Mst set C_Parent='@parent'
N_ptype=(select N_Type from Tbl_FS_Mst where C_Code='@parent') where
C_Code='@fscode'
end
GO
N:B:不确定在没有进一步使用sys.tables的情况下检查sys.tables有什么用。
希望,它有帮助:)
N:B: Not sure what is the use of checking sys.tables without using it further.
Hope, it helps :)
这篇关于如何在所有数据库中创建程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文