ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is Difference between jobs and function in sql server ?

user-image
تم إضافة السؤال من قبل amr nabih salah , Software Developer , Votake
تاريخ النشر: 2017/01/31
shakeel mir
من قبل shakeel mir , Senior Software Developer , Rawat-Al-Makan

It’s my point of view job and function are different thing is SQL SERVER I think, u may be ask the different between store procedure and function  What is Job?SQL SERVER Agent performed the different operations like running function T-SQL scripts and ActiveX scripts, Integration Services packages, Analysis Services commands and queries, or Replication tasks. Jobs can run repetitive or scheduled tasks, and they can automatically notify users of job status.Stored procedureSQL provides the stored procedure mechanism to simplify the database development process by grouping Transact-SQL statements into manageable blocks.

SP Function:

  • Precompiled execution
  • reduced client/server traffic,
  • efficient reuse of code and programming abstraction,
  • Enhanced security controls

User Defined FunctionsSQL Server user-defined functions and stored procedures offer similar functionality. Both allow you to create bundles of SQL statements that are stored on the server for future use. This offers you a tremendous efficiency benefitImportant differences between the two:

  • Stored procedures are called independently, using the EXEC command, while functions are called from within another SQL statement.
  • Stored procedure allow you to enhance application security by granting users and applications permission to use stored procedures, rather than permission to access the underlying tables. Stored procedures provide the ability to restrict user actions at a much more granular level than standard SQL Server permissions. For example, if you have an inventory table that cashiers must update each time an item is sold (to decrements the inventory for that item by 1 unit), you can grant cashiers permission to use a decrements item stored procedure, rather than allowing them to make arbitrary changes to the inventory table.
  • Functions must always return a value (either a scalar value or a table). Stored procedures may return a scalar value, a table value or nothing at all.

Mohammad Thanveer Ahmed Khan
من قبل Mohammad Thanveer Ahmed Khan , Software QA Lead / Manager , Cognizant Technology Solutions

  1. Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.

    Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.

  2. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.

    Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.

  3. Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

    Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.

  4. We can go for Transaction Management in Procedure whereas we can't go in Function.

Manjurul Islam Manju
من قبل Manjurul Islam Manju , Assistant Manager , Paramount Textile Ltd.

  1. Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).

  2. Functions can have only input parameters for it whereas Procedures can have input/output parameters .

  3. Functions can be called from Procedure whereas Procedures cannot be called from Function.

المزيد من الأسئلة المماثلة