Home I've generated an sql file full of inserts but can't find any documentation of executing this script from a stored procedure
Reply: 0

I've generated an sql file full of inserts but can't find any documentation of executing this script from a stored procedure

user831
1#
user831 Published in July 21, 2018, 9:48 am

I'm creating a stored procedure that will delete all the data in my database and then insert the data from my sql file. The reason I am using the delete and insert instead of a restore is because a restore requires that no one is connected to the database where as deleting and inserting allows people to still be connected.

Stored Procedure:

CREATE PROCEDURE DropAndRestore 
-- Add the parameters for the stored procedure here
@filepath nvarchar(200)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

-- Insert statements for procedure here
Exec sp_MSFOREACHTABLE 'delete from ?
RESTORE DATABASE [landofbeds] -- These lines are what needs to be replaced
FROM DISK = @FilePath         --
END
GO
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316934 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO