I have the following procedure which takes as parameter the name of database and the path and then creates a directory. My problem here I need override on the folder or delete it and then create a new one any idea of how to do such a thing
NOTE: this procedure creates in folder in depth of 0 and 1
ALTER PROCEDURE[dbo].[SP_CreateFolder]
@P_PATH VARCHAR(100),
@P_DBName VARCHAR(100)
AS
DECLARE @DBName sysname
DECLARE @DataPath nvarchar(500)
DECLARE @LogPath nvarchar(500)
DECLARE @DirTree TABLE (subdirectory nvarchar(255), depth INT)
-- Initialize variables
SET @DBName = @P_DBName
SET @DataPath = @P_PATH
-- @DataPath values
INSERT INTO @DirTree(subdirectory, depth)
EXEC master.sys.xp_dirtree @DataPath
SELECT * FROM @DirTree
-- Create the @DataPath directory
--IF (SELECT depth from @DirTree)!= 1
--EXEC master.dbo.xp_Delete_file @DBName
IF NOT EXISTS (SELECT 1 FROM @DirTree WHERE subdirectory = @DBName)
BEGIN
EXEC master.dbo.xp_create_subdir @DataPath
END
-- Remove all records from @DirTree
DELETE FROM @DirTree
sp_prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoidsp_and use something else as a prefix - or no prefix at all!