SQL Server vs. stored procedures

Source: Internet
Author: User
Tags tostring

This article illustrates the comparison of SQL Server with stored procedures from several perspectives.

Why do ① use stored procedures?

Because it executes faster than SQL statements.

What is the ② stored procedure?

With a bunch of SQL statements, you can also execute an SQL statement based on a condition.

③ to one of the simplest stored procedures:

CREATE PROCEDURE dbo.testProcedure_AX
AS
select userID from
USERS order by userid desc

Note: Dbo.testprocedure_ax is the name of the stored procedure you created, you can change it to: Axzhz and so on, do not conflict with the keyword on the line. As the following is a SQL statement, do not write SQL statements, please avoid.

④ How to call this stored procedure in asp.net:

public static string GetCustomerCName
(ref ArrayList arrayCName,ref ArrayList arrayID)
    {
      SqlConnection con=ADConnection.createConnection();
      SqlCommand cmd=new SqlCommand("testProcedure_AX",con);
      cmd.CommandType=CommandType.StoredProcedure;
      con.Open();
      try
      {
        SqlDataReader dr=cmd.ExecuteReader();
        while(dr.Read())
        {
          if(dr[0].ToString()=="")
          {
            arrayCName.Add(dr[1].ToString());
          }
        }
        con.Close();
        return "OK!";
      }
      catch(Exception ex)
      {
        con.Close();
        return ex.ToString();
      }
    }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.