Since SQL Server doesn't have packages, what do programmers do to get around it?

后端 未结 9 1497
有刺的猬
有刺的猬 2020-12-15 05:27

I have a SQL Server database that has a huge proliferation of stored procedures. Large numbers of stored procedures are not a problem in my Oracle databases because of the O

9条回答
  •  轮回少年
    2020-12-15 05:52

    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.

提交回复
热议问题