By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Saving changes

P: n/a
Hi, all.

This might be a silly question... but I am very new to programming in
SQL so please bear with me :)

So. I'm using MS SQL Server 2005 Management Studio Express. I have a
table that was created via an existing .sql file. Included were a
bunch of stored procedures. I went in to re-format these procedures.
(They were written in haste by another programmer. It is my task to go
back and improve their readabilities.) However, I am having difficulty
figuring out how to save the changes to these stored procedures. Thus
far, I have been individually saving each stored procedure in its
own .sql file. This is obviously not the way to go... but it's a
temporary solution (so as not to lose the changes I have made to
dozens of procedures).

Can someone please explain to me how I commit these changes to the
database?

Thanks,
Allie
Nov 20 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Allie (fa**********@gmail.com) writes:
So. I'm using MS SQL Server 2005 Management Studio Express. I have a
table that was created via an existing .sql file. Included were a
bunch of stored procedures. I went in to re-format these procedures.
(They were written in haste by another programmer. It is my task to go
back and improve their readabilities.) However, I am having difficulty
figuring out how to save the changes to these stored procedures. Thus
far, I have been individually saving each stored procedure in its
own .sql file. This is obviously not the way to go... but it's a
temporary solution (so as not to lose the changes I have made to
dozens of procedures).
I think that is exactly the way to go. You should also put the files under
source control.
Can someone please explain to me how I commit these changes to the
database?
But that's not saving. You save a file to the file system, and as I said,
you also put it under version control.

To change the database what's in the database is more akin to a compilation.
To make this easy to handle, I suggest that you have this in your files:

IF object_id('my_sp') IS NULL
EXEC ('CREATE PROCEDURE my_sp AS SELECT 1')
go
ALTER PROCEDURE my_sp -- real code follows here

Then it doesn't matter when you run the file, whether the procedure
exists or not.

And to run the file from Mgmt Studio, you can clich the green arrow,
or press CTRL/E or F5.

When you need to load several files, this is more convenient to do
from a BAT file and use SQLCMD instaead.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.