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. Stored Procedures or Direct SQL Statements

Stored Procedures or Direct SQL Statements

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
4 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.
  • E Offline
    E Offline
    emadns
    wrote on last edited by
    #1

    Hi, I wonder which is better using direct sql statments directly in the code or writing stored procedures inside the SQL Server database? What are the advantages and disadvantages of each? Thank you

    F C 2 Replies Last reply
    0
    • E emadns

      Hi, I wonder which is better using direct sql statments directly in the code or writing stored procedures inside the SQL Server database? What are the advantages and disadvantages of each? Thank you

      F Offline
      F Offline
      Frank Kerrigan
      wrote on last edited by
      #2

      stored procedures are compiled and operated much faster than free line code. Store procedures are also more secure Store procedure also let you modify the back end business logic without effecting your web or client applicated. Store procedures can be unit tested as a seperate business logic. Store procedure can return scaler values, tables , or action as action code. Store procedures can have error trapping and rollbacks if multiple tables need to be updates. Don't use free line SQL unless you can avoid it.

      1 Reply Last reply
      0
      • E emadns

        Hi, I wonder which is better using direct sql statments directly in the code or writing stored procedures inside the SQL Server database? What are the advantages and disadvantages of each? Thank you

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Stored Procedures are better in my opinion. Here are a couple of reasons: SPs mean that you can revoke the permissions on direct table access pushing everything through SPs. This means the only actions that an application can perform are only the actions the SPs permit. SPs can do additional checking of the data. This allows the database to weed out potentially dangerous data as part of a layered security approach. e.g. The application weeds out potentially harmful data first, but if that security layer should be compromised somehow the database itself has a layers of security to prevent dangerous actions - this includes logic within the SPs


        My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        Y 1 Reply Last reply
        0
        • C Colin Angus Mackay

          Stored Procedures are better in my opinion. Here are a couple of reasons: SPs mean that you can revoke the permissions on direct table access pushing everything through SPs. This means the only actions that an application can perform are only the actions the SPs permit. SPs can do additional checking of the data. This allows the database to weed out potentially dangerous data as part of a layered security approach. e.g. The application weeds out potentially harmful data first, but if that security layer should be compromised somehow the database itself has a layers of security to prevent dangerous actions - this includes logic within the SPs


          My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          Y Offline
          Y Offline
          Yulianto
          wrote on last edited by
          #4

          Show him your article colin. :)


          Work hard, Work effectively.

          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