views:

1451

answers:

5

I have SQL SERVER database that have a huge proliferation of stored procedures. In my Oracle databases it's not a problem because Oracle supports packages.

Even if SQL Server didn't support the cool features of packages like State and encapsulation, what do programmers do to get around this obvious deficiency?

+8  A: 

Come up with a good naming convention, use it, and enforce it.

James
+15  A: 

While SQL Server has nothing to offer by way of the "cool features" of encapsulation and package state like you are used to, you can organize your stored procedures into schemas.

In enterprise manager, these procs are still all listed together which makes for a HUGE treelist if you have hundreds of procs. I too miss the organization and cool features of Oracle packages. However, all platforms have their strengths.

NOTE: Writing stored procedures in the .NET language DOES give you encapsulation and state. It still does not however separate them in the EM treeview in any special way.

TheSoftwareJedi
I agree... I REALLY wish that I had TOP n and LIMIT queries in Oracle... that COOL feature of SQL Server is awesome. Alas, Packages are so important to code development, I'll live with the clunky rownum < construction.
Yeah, the paging in the queries is nice too in sql server (top 10..20) or something like that. Also, the EM application is great. As for packages being a die hard issue, I could think of MANY better reasons to use oracle over SQL Server. However, I could think of just as many in the other direction too... Cheers.
TheSoftwareJedi
@Jedi: Click the "Edited by" link in the question, and you'll see who locked it. I don't see why, as it really quieted down after comment #100.
John Saunders
@John Saunders because you all are power hungry elites whom just like to squash foreign ideas and debates. Sorry to say it, but I'm out. Jeff locking this question was the last straw. NO REASON TO LOCK. It'sz like he has a report of hot questions and just goes through them to see if people are arguing and silences them. We don't want any disagreement here on SO! Everyone needs to follow the party line. Fucking politics, and against the original spirit of SO.
TheSoftwareJedi
@TheSoftwareJedi, this post is probably locked because of the number of edit reverts. It has happened in the past and has nothing to do with the contents. If you want more information, send a mail to [email protected].
Gamecat
@Gamecat - the edit wars were 12 hours before this was closed... And if the locker read the comments he'd see we all reached an agreement of sorts. team@so already got an email. Thanks.
TheSoftwareJedi
Holy shit I think we have just found the epitome of butthurt on StackOverflow. Calm...the...hell...down.
TheTXI
@TheTXI yeah, was quite fun... :)
TheSoftwareJedi
"If I want to spend my evening and day arguing about if packages in Oracle are better than no packages in SQL server, why should Jeff, or the SO team care?" well, because you just said it...you are arguing. And Jeff and the team feel that things which are incredibly subjective and argumentative (and don't have anywhere close to an actual answer) should not be allowed on this site, and then leaves it up to the community to police that policy. It's Jeff's site and his rules.
TheTXI
and BTW...railing against a community moderated and community edited website like StackOverflow for being Socialist is hilarious.
TheTXI
@TheTXI - hey now, you and I both know that the top 73 users are actually creations of Jon Skeet so he can gain rep beyond the daily cap.
Adam Davis
This answer isn't nearly as amusing at it was prior to the rant being rolled back.
TheTXI
@TheTXI Nothing close to an answer? Really? Is not THIS ANSWER close to an answer? In fact, it started a great dialog with Mark.
TheSoftwareJedi
I've completely lost track over what the hell you are talking about.
TheTXI
@Adam Davis, I'm not a creation of Jon Skeet, and even if I am, I'm still in denial.
Gamecat
@Gamecat: Apparently Jon Skeet gave you enough sentience to doubt your own existence.
TheTXI
@Gamecat - <shifty eyes> Yeah, yeah, of course. I'm not one either... </shifty eyes>
Adam Davis
@Jedi: Dude you need help
belgariontheking
@TheTXI, Adam Davis, and Rich B: Are you guys *trying* to get this post locked?
Michael Myers
@mmyers - Actually this particular answer needs to be deleted, as the OP keeps putting the offtopic rant inside, and rolling it back whenever we edit it back on topic.
Adam Davis
@Adam Davis: Let's see -- (checks revision history) So he did. Once. (TheTXI did it once also, but that appears to have simply been clobbering Rich B's rollback.)
Michael Myers
@TheSoftwareJedi: I understand you are unhappy about the situation, but please don't put offtopic meta information into the answer itself. Bring it to uservoice, email team@stackoverflow, etc, but please keep this question on topic.
Adam Davis
@Adam Davis - I'd like it to be in the comments to the question, but the question is locked :). I'll remove it. Bon Voyage.
TheSoftwareJedi
@TheSoftwareJedi: Do not keep putting your rant into your answer. Bring this to the attention of [email protected] if you feel is a problem.
Samuel
@tried to rollback, but someone beat me to it.
TheSoftwareJedi
@samuel - already brought to their attention. yeah, that's useful. it's like writing my congressman. as if they read it.
TheSoftwareJedi
@TheSoftwareJedi: Thanks.
Adam Davis
@TheSoftwareJedi: Just leave this question then. Just ignore *anything* that happens here. Let the moderators take proper action.
Samuel
@TheSoftwareJedi: Actually, they do, and they take action in many cases. Most of the time they'll wait to see if it resolves itself, though...
Adam Davis
May I suggest taking a look at http://stackoverflow.uservoice.com/pages/general/suggestions/106921-provide-an-authorized-location-for-meta-discussion- ?
Jon Ericson
@Samuel I AM a moderator. As are all of us. Why would I ignore a question I'm interested in?
TheSoftwareJedi
@TheSoftwareJedi: We are not moderators. The people that read [email protected] are moderators. We are editors.
Samuel
Why are people still flagging this? It's no longer flag worthy, IMHO.
Adam Davis
+4  A: 

Schemas may be used to organize stored procedures and other objects. Personally, I prefer to use schemas when they organize objects by functional area, and where those funcational areas correspond to security boundaries. An example of this is found in the AdventureWorks sample databse, which has schemas like "HumanResources" and "Sales". The theory being that a given user may need access to objects in "HumanResources", but may not need access to "Sales" information.

An alternative is to use a naming convention and enforce it, as James says above. I'll add that SQL Server Management Studio has a filter button that can be used to filter the list of objects displayed. For instance, one can click on the "Stored Procedures" folder and filter on Name contains "Add".

On my current project, I have pulled a number of SQL queries out of SSIS packages and into stored procedures. In order to distinguish between these stored procedures and those that should be of general use, I have prefixed the names with "ssis". It would certainly have been more pleasant if I could have created something similar to a namespace in C# or C++, and created "SSIS.SelectUserLookupData" instead of "ssis_SelectUserLookupData". It would be even nicer if these namespaces could be nested.

If this is one of the featues of Packages in Oracle, then perhaps someone would let me know.

John Saunders
I like how you provide an answer to a question that you closed as "not a question". Truly classy.
TheSoftwareJedi
@Jedi: I don't see how to win with you. Once the Community decided, by reopening, that this _was_ a question, I've _treated_ it like a question, and contributed something that I don't think was previously present. If someone actually finds this question looking for help, I think my answer may help a little. It comes from my experience, as opposed to the "rewrite" we discussed and I decided against.
John Saunders
@John Saunders: so you actually needed other people to tell you this is a question?! lol
TheSoftwareJedi
@Jedi: I needed someone else to help me ignore the snobbish attitude in the original question, and hear the question the way it should have been asked.
John Saunders
+1  A: 

I would thank my lucky stars that SQL Server doesn't have packages. Oracle packages suck.

Hmm, we need a way to take all these procedures and put them in one place. I know! Let's make developers create and maintain two files for each package. They will love us forever!

As long as MS never implements packages like Oracle did, it'll be a win in my book.

EDIT for commenters:

Oracle Packages are simply a way to organize your stored procedures into, well, packages so that you don't have 100 stored procedures sitting around, but maybe 5 packages. They're not stackable like packages in Java or C# code. All packages are at the same level.

A package requires two files: the headers file and the body file. This creates frustration when adding new procedures to an existing package, because you cannot add the body without adding the header, even though it contains the exact same information as is in the body.

For example, here is a snippet from the header file of one of my packages:

    PROCEDURE bulk_approve_events
(
 i_last_updated_by IN VARCHAR2,
 o_event OUT NUMBER
);

And here's the corresponding procedure in the body:

    PROCEDURE bulk_approve_events
(
 i_last_updated_by IN VARCHAR2,
 o_event OUT NUMBER
) IS
...
BEGIN
...
END;

No difference. The header file is useless and is simply another hurdle for the developer to step over when developing with packages. On my project, we have a convention that all the commented documentation for each procedure goes in the header, along with the details of when it was added and by whom, but that could just as easily be included in the body.

belgariontheking
@Puppies: Could you expound on that for those of us who don't know what packages are? It would be more helpful if you left out the emotion. If Oracle packages suck, they'll still such just as much if you describe them in a less emotional manner.
John Saunders
Packages don't require two files... in fact they don't require any files. The create package statements are understood by the oracle interpreter and can be sent over any database connection.
Mark Harrison
Why distinct package headers and bodies? Because the bodies can be implemented in other languages such as C or Java. Additionally, the declaration is where you put the public interface. Procedures and functions not in the public interface can't be called from outside the scope of the package.
Mark Harrison
@Mark: in my post, statement == file. I have to go to two places to add a procedure to a package, and that's annoying and very broken IMO
belgariontheking
A: 

I've worked with both SQL Server and Oracle so have seen the good and bad of both. As the above comments have beena bit heated I'll try and keep this as neutral as possible...

So, what's an Oracle Package? Think of it like a database class

The Package has two elements: a header file and a body file. The header file is your public interface, and contains the signature (name, params and return type if applicable) of all the stored procedures or functions (in Oracle a function returns a value, a stored proc doesn't) that are directly callable. The package body must implement all the procedure signatures in the package header file.

The body element of the package contains all the stored procs and logic that actually do the work. You may have a Save procedure declared in the package header that calls an insert or update proc that exists in the body. The developer can only see the "Save" proc. It's important to keep in mind that the package body can also implement procs or functions not declared in the package header, they're just not accessible outside of the package itself.

I found packages to be really useful for a number of reasons:

  1. You've got the concept of a public interface that can be provided to other developers
  2. Packages can mirror your compiled classes. My Orders.Save() C# method will call my Oracle Orders.SaveLineItem method to save each line item and an Oracle SaveOrder method to save the order summary details.
  3. My procs are grouped together in a nice, logical way inside the packages

Personally, I would be love MS to implement some kind of package functionality as I think it makes for a cleaner database.

gadsUK