?
Solved

Copy store procedure to another database?

Posted on 2004-10-17
11
Medium Priority
?
754 Views
Last Modified: 2008-02-20
I have some store procedure in a database. I usually have to create new database and have to create the sp above into new database. Can you tell me how to automate all that work:
- create new database
- copy some sp from old db to new db

I have SQL2K and coding all in Visual Basic.

Thanks

0
Comment
Question by:tungduong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 3

Expert Comment

by:AlphaMan74
ID: 12335878
You want a complete copy of the database, with all tables, Stored Procedures and data? Or an empty database with all tables and SPs? Or something else?

To get all tables, Stored procedures and data, you can backup the database in enterprise manager then restore it under the new database name. Let us know if you need some further help with that.

If you want an empty database, then what you want to do is script the database in enterprise manager, then save that script. Change the name of the database in the CREATE DATABASE part of the script before you run it. Again, if you need detailed instructions, post back and we can help.
0
 
LVL 34

Accepted Solution

by:
arbert earned 500 total points
ID: 12335979
To expand a bit, if you want to create a script,  Open enterprise manager, right click on your database, Choose All Tasks, Generate SQL Scripts.  You can choose to script the database and choose the stored procs you want to script.

So, if you wanted to code it from VB, you could use the above script and execute it against an ADO connection object.

Brett
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 12336649
If you REALLY want to do this in VB (Its only a few Clicks in EM like arbert said) you should look at the SQLDMO object which is installed when you install the SQL-Server-Connectivity.

This object allows you to list all SP's and Tabels in an SQL Server (well actually you can do anything you want in it with it....) I think it can also generate the code you need to script the SP and tabels. But i would not go this way since it is so easy in EM :=)
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:tungduong
ID: 12337061
Thanks t all of help.

My problem is I have database with meny table and store procedure in it. Each month I have to create new database and want to restore all store procedure and some table (not all the tables). The store procedure then may be modify by the SQL Server admin (it rearly change) With the table I can excute command
SELECT .. INTO...
to transfer data to new database. The problem is I dont know how to do with the store procedures.

0
 
LVL 34

Expert Comment

by:arbert
ID: 12337924
"Each month I have to create new database"

Sounds like a maintenance nightmare....
0
 

Author Comment

by:tungduong
ID: 12343467
I've heard that sql_helptext can solve the problem. So can you tell me how to do with it in VB6?
0
 
LVL 34

Expert Comment

by:arbert
ID: 12343879
You mean sp_helptext?

sp_helptext just returns the SQL for a routine/proc or the text of a view.  You could use it in VB--simply execute it with the connection object and pass the "object" as a parameter for which you want the text back (you can assign a recordset to get the results).

set rs=conn.execute ("sp_helptext 'yourstoredprocnamehere'")
0
 

Author Comment

by:tungduong
ID: 12344111
Thanks, arbert. I can you tell me how to run .sql script file from visual basic if I use your first guide to generate a script which content all of my store procedure.
I save script to name: create_sp.sql
I try to run with command:
gConn.Excute("EXEC ") & App.Path & "\create_sp.sql"
But it failed.

0
 
LVL 34

Expert Comment

by:arbert
ID: 12344461
You would actually have to read the contents of the file into a variable and exec that....the execute method (you have .Excute, but I assume that's a typo) won't read a file...
0
 

Author Comment

by:tungduong
ID: 12355797
I did as you said, arbert, but it fial to excute. You now there are much of quote (') mark in the store procedure.

How can I do?
0
 

Author Comment

by:tungduong
ID: 12366066
Well, thanks alot. I can do it now.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question