Wednesday, March 21, 2012

Saving a function in Management Studio

Hi,

I know this will be a very easy question to answer but I cannot figure it out. I'm REAL new to both SQL 2005 and Management Studio.

I just created my first User Defined Function. Here is how I did it. In the left window of Studio, I right clicked on the folder "Scalar vauled functions" and selected "New Scalar vauled function". This action brought me up in Query Editor. I composed my function and went to save it (Save As) and it gave me a default file name with a suffix of ".sql" which I thought a bit odd but went ahead and saved it. Now when I go to open that function, it has the standard SQL Query icon assigned to it. There are other existing functions on this system which have a small "fx" icon assigned to them - thus I'm thinking I didn't either save it to the right place, I needed to compile it first or something else. Also, it saved it to a folder called "Pjojects" on my PC.

What am I doing wrong?

Thanks,

Bruce

When you're finished with your function, hit F5...don't use Save As. Save As is asking you where you want to store a text version of the function. For example, if you wanted to store a query you run a lot, you'd select Save As, then open the text file anytime you wanted to run it. Functions, Stored Procedures, Views, etc... you want to be stored on the server. So you execute them initially using the CREATE keyword, and make changes but changing CREATE to ALTER and always use F5 not Save As.

Adamus

sql

No comments:

Post a Comment