Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Does it make sense to use CLR Stored Procedures

Does it make sense to use CLR Stored Procedures

Scheduled Pinned Locked Moved Database
csharpsharepointdatabasesql-serverdotnet
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jani Giannoudis
    wrote on last edited by
    #1

    I'm playing with the idea to build a sample, on how to integrate the Time Period Library for .NET into the SQL Server. So far I have build a demo library/assembly/procedure and does some time period calculations using the AdventureWorks catalog ... and it works :). Because I have little experience using CLR SP, here my questions: - Makes this integration sense to reduce the complexity of T-SQL programming? - What's the performance difference between CLR SP and T-SQL?

    Jani Giannoudis


    Latest article: Time Period Library for .NET

    W P W 3 Replies Last reply
    0
    • J Jani Giannoudis

      I'm playing with the idea to build a sample, on how to integrate the Time Period Library for .NET into the SQL Server. So far I have build a demo library/assembly/procedure and does some time period calculations using the AdventureWorks catalog ... and it works :). Because I have little experience using CLR SP, here my questions: - Makes this integration sense to reduce the complexity of T-SQL programming? - What's the performance difference between CLR SP and T-SQL?

      Jani Giannoudis


      Latest article: Time Period Library for .NET

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      From what I have read, the CLR SP seems to actually return data quicker than T-SQL but that it becomes much harder to maintain your application. Before going this route you need to determine which is more important, speedy data return, or application maintenance.

      1 Reply Last reply
      0
      • J Jani Giannoudis

        I'm playing with the idea to build a sample, on how to integrate the Time Period Library for .NET into the SQL Server. So far I have build a demo library/assembly/procedure and does some time period calculations using the AdventureWorks catalog ... and it works :). Because I have little experience using CLR SP, here my questions: - Makes this integration sense to reduce the complexity of T-SQL programming? - What's the performance difference between CLR SP and T-SQL?

        Jani Giannoudis


        Latest article: Time Period Library for .NET

        P Online
        P Online
        PIEBALDconsult
        wrote on last edited by
        #3

        It certainly can, but have you considered user-defined functions?

        J 1 Reply Last reply
        0
        • P PIEBALDconsult

          It certainly can, but have you considered user-defined functions?

          J Offline
          J Offline
          Jani Giannoudis
          wrote on last edited by
          #4

          Implicitly, yes. The question is if it makes sense to provide a library which supports time operations for database tables. Something like: Overlaps( startDateColumnName, endDateColumnName, testPeriodStartDate, testPeriodEndDate ); usage: SELECT * FROM Bookings WHERE Overlaps( 'Start', 'End', '20110101', '20110331' ) Another sample may be: GetGaps( tableOrViewName, startDateColumnName, endDateColumnName, searchStartDate, searchEndDate ); usage: EXEC GetCaps( 'Bookings', 'Start', 'End', '20110101', '20110331' ) -- return all gaps

          Jani Giannoudis


          Latest article: Time Period Library for .NET

          P 1 Reply Last reply
          0
          • J Jani Giannoudis

            Implicitly, yes. The question is if it makes sense to provide a library which supports time operations for database tables. Something like: Overlaps( startDateColumnName, endDateColumnName, testPeriodStartDate, testPeriodEndDate ); usage: SELECT * FROM Bookings WHERE Overlaps( 'Start', 'End', '20110101', '20110331' ) Another sample may be: GetGaps( tableOrViewName, startDateColumnName, endDateColumnName, searchStartDate, searchEndDate ); usage: EXEC GetCaps( 'Bookings', 'Start', 'End', '20110101', '20110331' ) -- return all gaps

            Jani Giannoudis


            Latest article: Time Period Library for .NET

            P Online
            P Online
            PIEBALDconsult
            wrote on last edited by
            #5

            If you use them a lot then sure. On my last job I made a database that contained only user-defined functions that I then used in many queries from many databases. User-defined table-valued functions combine the best of views and stored procedures -- they're like views that can take parameters.

            J 1 Reply Last reply
            0
            • P PIEBALDconsult

              If you use them a lot then sure. On my last job I made a database that contained only user-defined functions that I then used in many queries from many databases. User-defined table-valued functions combine the best of views and stored procedures -- they're like views that can take parameters.

              J Offline
              J Offline
              Jani Giannoudis
              wrote on last edited by
              #6

              The idea is to provide a generic library with predefined SPs and UDFs that can be used for complex time period calculations (inside, overlap, gap, intersection...). For example:

              EXEC TimePeriodInfo
              @table = 'HumanResources.vEmployeeDepartmentHistory',
              @startDateField = 'StartDate',
              @endDateField = 'EndDate'

              returns (only fake sample):

              periods:
              05.01.1998 - 30.06.2000 | 907.00:00
              20.01.1998 - 15.08.1999 | 572.00:00
              08.02.1999 - 01.10.2001 | 966.00:00
              04.03.1999 - 15.12.2003 | 1747.00:00
              28.03.2001 - 30.08.2001 | 155.00:00
              31.08.2001 - 15.08.2002 | 349.00:00
              intersected periods:
              20.01.1998 - 15.08.2002 | 1668.00:00
              combined periods:
              05.01.1998 - 15.12.2003 | 2170.00:00

              Jani Giannoudis


              Latest article: Time Period Library for .NET

              1 Reply Last reply
              0
              • J Jani Giannoudis

                I'm playing with the idea to build a sample, on how to integrate the Time Period Library for .NET into the SQL Server. So far I have build a demo library/assembly/procedure and does some time period calculations using the AdventureWorks catalog ... and it works :). Because I have little experience using CLR SP, here my questions: - Makes this integration sense to reduce the complexity of T-SQL programming? - What's the performance difference between CLR SP and T-SQL?

                Jani Giannoudis


                Latest article: Time Period Library for .NET

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Hi, CLR procedures are handy and the programmability is much wider than using plain T-SQL. However, depending on the specs it may/may not be wise to use them. Few thoughts: - if you're working with sets (possibly with large amount of rows), building a procedure or function that works row-based may cause intolerable response times. SQL is very good in set based operations (it's designed for that :)). - if you need calculations, complex logic etc then the programmability of .Net will offer much more possibilities over SQL and it may be a better option. Based on the examples you've written, they may be fairly easy to do with SQL using proper conditions etc and in that case the performance would be far better. But as they were only examples I'm not able to say if that's really the situation. A good rule of thumb could be that there's usually no need to replace such functionality with CLR operations that already exists in SQL itself unless there's some other benefits and not too much downsides. :) Best regards, mika

                The need to optimize rises from a bad design.My articles[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups