1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

why/when Do I need stored Procedures?

Discussion in 'Databases' started by progfrog, Dec 16, 2008.

  1. #1
    Hi!

    I'm building a website with a database .
    The users would be able to insert data through user interface. This data would be inserted in tables in the db. The same data could be rertived according to the search options. It supposed to be used like the add classfied
    website.


    Everyone tell me that i have to use stored procedures in my db. why do i need it? why can't i use a simple "insert" query in order to take the data from the user


    Plz give ne a good explanation[/COLOR]

    Progfrog
     
    progfrog, Dec 16, 2008 IP
    rajib.bahar likes this.
  2. Sapphiro

    Sapphiro Well-Known Member

    Messages:
    1,242
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    175
    #2
    You're developing an ASP.NET site rite? Well then there's nothing wrong, you'll definitely need to create stored procedures. Basically stored procedures are like "methods" for SQL statements to interact with your database, so let's say when you need your page to be able to create a new user for example, you'll call a method from your c# codes which will then execute the corresponding stored procedure with the inputs as the variables. :)
     
    Sapphiro, Dec 16, 2008 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    You don't need to use SP's. They can make development a lot easier and queries a lot quicker because you are eliminating a lot of the site -> database transfer, but you don't have to have them.

    They're most useful when the same query will have to be run many different times. They are also convenient on highly complex queries that junk up your application, and may later change. Depending on how you use them they are also great for creating a more stable application environment, because you can change the query externally as long as the interface remains the same.
     
    jestep, Dec 16, 2008 IP
  4. rajib.bahar

    rajib.bahar Active Member

    Messages:
    87
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #4
    Here are some of the reasons why stored procedures are recommended:
    1. SQL Server stores your execution plan... This is what makes the query to run faster in subsequent execution
    2. It's more secured to use Stored Proc. The security issue comes up when you are using dynamic sql. The end user could manipulate your query from the webapp. Using storedproc programmatically forces the programmer to use parameter. This in turn can avoid the malicious input.
    3. You're acting in disciplined manner and conforming to best practice known to the SQL Server community.
     
    rajib.bahar, Dec 18, 2008 IP
  5. kappaknight

    kappaknight Peon

    Messages:
    160
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    However, if you want to code a simple, small site, you don't need to use stored procedures. It's one less place to debug when testing your app.
     
    kappaknight, Dec 22, 2008 IP
    rajib.bahar likes this.