Sunday, July 28, 2013

Saving a Stored Procedure created from MSSMS Script fails

Hi,


I wanted to create a SP that would create a fresh database for testing.


I used MSSMS to script the existing data base (currently Schema objects including Stored Procedures but no data as yet).


I changed all references to the original DB e.g. changed dbA to dbB and


I changed the USE master to USE dbA and added the lines to create a Stored Procedure tried to save it .


I am getting a lot of errors such as:


Msg 15023, Level 16, State 1, Line 2

User, group, or role 'AppUser' already exists in the current database.

Msg 219, Level 16, State 1, Line 2

The type 'dbo.SalesReportTable' already exists, or you do not have permission to create it.

Msg 2714, Level 16, State 3, Procedure backup_appdb, Line 6

There is already an object named 'backup_appdb' in the database.


etc.


I understand why this is erroring but not sure how to approach a solution.


I want to have a SP I can call, anytime, to create a copy with all tables, SPs etc and with some system data but without most of the User data. So I do not want to do a back-up and restore to a new DB. And I would like to automate is so rather than using MSSMS to create the script each time and then change and run it (which works well), I wanted a SP that would delete the 'Test' db if it exists, and then create a new 'Test' db and then create all the tables, SPs etc.


I would appreciate any advice,


Thanks




Regards Doug Bell


No comments:

Post a Comment