今天遇到了一個問題,需要把原數(shù)據(jù)庫的一些數(shù)據(jù)導入到新數(shù)據(jù)庫中,其中包括700多條存儲過程。
開始通過sql語句查詢出所有的存儲過程,然后再創(chuàng)建,發(fā)現(xiàn)創(chuàng)建存儲過程時不能同時創(chuàng)建多個。

select sm. object_id , object_name (sm. object_id ) as object_name , o.type, o.type_desc, sm.definition from sys.sql_modules sm inner join sys.objects o on sm. object_id = o. object_id where o.type = ' P ' and o.name not like ' %diagram% ' order by o.name;
如果想要同時創(chuàng)建多個存儲過程,需要在每個存儲過程之間加入"go",然后再執(zhí)行。
后來通過高人指點,用下面的sql語句備份原數(shù)據(jù)庫的存儲過程,再在新數(shù)據(jù)庫執(zhí)行即可。

create table #sql_modules(id int identity ( 1 , 1 ), definition nvarchar ( max )) insert into #sql_modules select sm.definition from sys.sql_modules sm inner join sys.objects o on sm. object_id = o. object_id where o.type = ' P ' and o.name not like ' %diagram% ' order by o.name; declare @counter int = 1 declare @max_count int = ( select max (id) from #sql_modules); declare @sql_modules table (definition nvarchar ( max )) while @counter <= @max_count begin insert into @sql_modules select definition from #sql_modules where id = @counter union all select ' go ' set @counter = @counter + 1 ; end select * from @sql_modules ; drop table #sql_modules;
?
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
