create procedure #pr_CreateFileGroup @dbname nvarchar(max), @filegroupname nvarchar(max) as begin /* 腳本來源:https://www.cnblogs.com/zhang502219048/p/121 ...
create procedure #pr_CreateFileGroup @dbname nvarchar(max), @filegroupname nvarchar(max) as begin /* 腳本來源:https://www.cnblogs.com/zhang502219048/p/12105527.html 腳本作者:zhang502219048 功能:通過創建臨時存儲過程拼接SQL語句,實現創建文件組語句可以傳遞參數,避免寫重覆代碼段,實現腳本代碼的封裝復用。 */ declare @sql nvarchar(max) select @sql = ' if not exists (select 1 from sys.filegroups where [name] = ''' + @filegroupname + ''') begin alter database ' + @dbname + ' add filegroup ' + @filegroupname + ' end ' print @sql exec sp_executesql @sql end go -- ================================================================================================ --調用臨時存儲過程,創建文件組 exec #pr_CreateFileGroup 'DB_Test2', N'Project_data' exec #pr_CreateFileGroup 'DB_Test2', N'Project_index' -- ================================================================================================
腳本運行情況:
資料庫中文件組添加效果: