SQL Server Functions ================= A function, in any - TopicsExpress



          

SQL Server Functions ================= A function, in any programming environment, lets you encapsulate reusable logic and build software that is composable, i.e. built of pieces that can be reused and put together in a number of different ways to meet the needs of the users. Functions hide the steps and the complexity from other code. However, in certain respects, SQL Servers functions are fundamentally different from functions in other programming environments. In procedural programming, the piece of functionality that most programmers call a function should really be called a subroutine, which is more like a miniature program. These subroutines can go about changing data, introducing side effects, and generally misbehaving as much as they like. In SQL Server, functions adhere much more closely to their mathematic definition of mapping a set of inputs to a set of outputs. SQL Servers functions accept parameters, perform some sort of action, and return a result. They do all of this with no side effects. Nevertheless, in the same way as subroutines, SQL Server functions can hide complexity from users and turn a complex piece of code into a re-usable commodity. Functions make it possible, for example, to create very complex search conditions that would be difficult and tedious to express in inline T-SQL. Fun Facts about Functions ----------------------------------- This section describes, briefly, some of the basic characteristics of the various types of SQL Server function, which well explore in more detail as we progress through the later examples. As noted in the introduction, all SQL Server functions adhere closely to the mathematic definition of a function i.e. a mapping of inputs to outputs, without have side effects. A function with inputs x and y cannot both return x + y and modify the original value of y. As a matter of fact, that function couldnt even modify y: it is only able to return a new value. Where Can I Use A Function? ---------------------------------- Anywhere! Well, we can use a function almost anywhere that we would use a table or column. We can use a function anywhere that we can use a scalar value or a table. Functions can be used in constraints, computed columns, joins, WHERE clauses, or even in other functions. Functions are an incredibly powerful part of SQL Server.
Posted on: Mon, 15 Sep 2014 12:34:37 +0000

Trending Topics



Recently Viewed Topics




© 2015