Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Import/Export Stored Procedures

Author  Topic 

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-03 : 09:59:43
Is there anyway to import/export stored procedures instead of backing up the whole database? Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-03 : 10:07:38
See if this helps
http://sqljunkies.com/WebLog/madhivanan/archive/2005/09/27/16914.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-03 : 10:40:25
Hi,

I replied at the link you provided. I didnt take notice of your username and didnt know that you were the one who posted that script.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-01-03 : 10:50:38
You could generate SQL scripts for all sp objects
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-03 : 10:53:31
Only displays the first 4000 characters doesn't it Madhi? Or am I doing something daft?

I was trying:

Select routine_definition from DBname.information_Schema.routines order by routine_name

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-04 : 00:52:34
>>Only displays the first 4000 characters doesn't it Madhi?

I am not sure on that
If thats the case, then I would prefer Generate Script approach

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-04 : 01:19:42
sp_help syscomments shows syscomments.text is nvarchar(8000)

-----------------
[KH]

2006 a new beginning
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-04 : 01:28:19
I tried to use your query above to save my stored procedures in a script. How will i be able to get the stored procedures in the script into another database? And is it possible to select which stored procedure to export? However, i met with the following errors:

Password:
SQLState = 37000, NativeError = 170
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'Assistant'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
NULL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-04 : 03:05:11
Post the query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-04 : 08:03:26
"sp_help syscomments shows syscomments.text is nvarchar(8000)"

except that 'coz its nvarchar the "length" parameter has to be divided by 2 - so its nvarchar(4000)

syscomments stores successive "blocks" of the code in additional records. However, sp_helptext fails to stitch them together properly (it incorrectly inserts a CR LF between each "block"). But generating a script in EM doesn't have this failing, so it must be doing something smarter!

"How will i be able to get the stored procedures in the script into another database"

Just EXECute them on the "other" database??

"And is it possible to select which stored procedure to export?"

Enterprise Manager can generate a script for all the objects in the database (right click the database, "All tasks", "Generate SQL"). You could choose just the SProcs you want, and then have E.M. generate you a script (or it can put each object into a separate file, if you prefer)

Kristen
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-04 : 12:52:37
exec master..xp_cmdshell
'bcp "Select routine_definition from Interactive Store Assistant.information_Schema.routines order by routine_name" queryout "C:\Documents and Settings\Valerie\Desktop\scripts.sql" -c'
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-04 : 12:56:48
Kristen: I didnt know that Enterprise Manager can select exactly which stored procedure to export. Thanks a lot!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-04 : 13:10:21
"I didnt know that Enterprise Manager can select exactly which stored procedure to export. Thanks a lot!"

No problem!

"exec master..xp_cmdshell ..."

If you have a space in your database name you have to enclose it in [My DB Name] (same with table and column names):

exec master..xp_cmdshell
'bcp "Select routine_definition from [Interactive Store Assistant].information_Schema.routines order by routine_name" queryout "C:\Documents and Settings\Valerie\Desktop\scripts.sql" -c'

Kristen
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-04 : 13:38:15
Oh ... Thanks a lot! Works like a charm!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-05 : 02:03:36
It is better practice to avoid having space in the objects names that can lead you unnecessary problems. Instead use Underscore (_) in place of space for better readability

You are good to go if you have Interactive_Store_Assistant

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-05 : 02:21:20
Okay thanks, i will take note of that.
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-22 : 03:43:30
I have managed to copy the stored procedures successfully. But cant seem to export into another database. I tried to use import/export data but it does not work. Can someone help me out. Thanks
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-22 : 08:40:31
Generate a script, and run it on the other database.

Not sure what you mean by "I have managed to copy..." and "... cant seem to export into another database"

Kristen
Go to Top of Page

shaoen01
Yak Posting Veteran

78 Posts

Posted - 2006-01-22 : 19:29:47
My "managed to copy ..." means that i have generated the script already. But when i use the import/export wizard to help me to import the script into another database it does not work.

So what i did was to copy the script generated and executed it in the query analyzer and it works. I thought it could be done by using the wizards though.


quote:
Originally posted by Kristen

Generate a script, and run it on the other database.

Not sure what you mean by "I have managed to copy..." and "... cant seem to export into another database"

Kristen

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-22 : 19:49:33
Use Query Analyser, connect to your destination database, load your script and run

-----------------
'KH'

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-23 : 02:07:06
"So what i did was to copy the script generated and executed it in the query analyzer and it works"

Yup, that's the best way. I don't think you can use import/export wizard.

Kristen
Go to Top of Page
    Next Page

- Advertisement -