Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Server and Database Auditing in SQL Server 2008
So, you find yourself On-Call
Administrator & Monitoring Change Data Capture in SQL Server 2008 ...
Importance of the Resource Database

More     
 
Latest FAQ's

SQL Server Reporting Server (SSRS) service is failing to start ...
Cannot Start SQL Server Service
Users are able to connect to report manager but not able ...
Errors when SQL Server Snapshot Replication is Running

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> developer >> An Introduction to SQL Server Scalar UDFs ...

An Introduction to SQL Server Scalar UDFs

By : Navneeth Diwaker Naik
May 17, 2004

Page 3 / 4

Unlike stored procedures, scalar functions can also be created using the option SCHEMA BINDING and ENCRYPTION, as shown below:

CREATE FUNCTION fnSchemaTest

(

             @EmailId varchar(255)

)

RETURNS varchar(100)

WITH SCHEMABINDING

AS

BEGIN

       DECLARE @FullName varchar(100)

       SELECT @FullName  = [FT_FName] + ' ' + [FT_LName]

            FROM dbo.FunctionTest

       WHERE [FT_EMail] = @EmailID

       RETURN @FullName

END

The addition of columns is allowed, as shown below:

ALTER TABLE dbo.FunctionTest

ADD [Active] bit

The deletion of a newly added column is allowed, as shown below:

ALTER TABLE dbo.FunctionTest

DROP COLUMN [Active]

The deletion of column being referenced in the function with SCHEMA BINDING is not allowed, as shown below:

ALTER TABLE dbo.FunctionTest

DROP COLUMN [FT_FName]

Output:

Server: Msg 5074, Level 16, State 3, Line 1

The object 'fnSchemaTest' is dependent on column 'FT_FName'.

Server: Msg 4922, Level 16, State 1, Line 1

ALTER TABLE DROP COLUMN FT_FName failed because one or more objects access this column.

Since the columns FT_FName is being used in Function with SCEHEMA binding we cannot DROP it.

CREATE FUNCTION fnEncrypTest

(

             @EmailId varchar(255)

)

RETURNS varchar(100)

WITH ENCRYPTION

AS

BEGIN

        DECLARE @FullName varchar(100)

        SELECT @FullName  = [FT_FName] + ' ' + [FT_LName]

               FROM dbo.FunctionTest

               WHERE [FT_EMail] = @EmailID

       RETURN @FullName

END


<< Prev Page     Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved