Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to transfer stored procedures between SQL Server 2005 databases

I'm creating web site on local computer. i'm using SQL Server 2005 management studio. I need to copy all data to destination server. Destination server is SQL Server 2005. My problem is

  1. when i using import/Export data for management studio, this only copy tables.
  2. when i using backup and restore, tables and stored procedure shows like this

myuser.aspnet_application

myuser.aspnet_Membership ... etc. I need to create like this

dbo.aspnet_application

dbo.aspnet_Membership

How to copy stored procedures and views to destination server?

like image 259
ebattulga Avatar asked Apr 03 '09 07:04

ebattulga


People also ask

How do I move a stored procedure from one database to another in SQL Server?

Launch MS SQL Server Management Studio in your system and go to the Object Explorer. Step 2. Right-click on the database from which you want to move data and then click on Tasks>>Generate Scripts… A Generate and Publish Scripts Wizard will appear on the screen, click on the Next button to proceed.

Can a stored procedure access another database?

You can work around this in SQL Server by creating a stored procedure that accesses data in another database and signing the procedure with a certificate that exists in both databases. This gives users access to the database resources used by the procedure without granting them database access or permissions.


1 Answers

In SQL Server Management Studio navigate to your database.

Right click it and select "Tasks" -> "Generate Scripts"
"Next"
Select your database from the list
"Next" Select "Stored Procedures" "Next"
"Select All" "Next"
"Script to new Query Window" "Next"
"Finish"

Give it a while. Then when complete, at the very top of the script put "use (yourdatabase)"

Execute the use statement.
Execute the whole script.

like image 184
Dead account Avatar answered Nov 14 '22 21:11

Dead account