1

I have come across a situation where functions are very helpful. I can create it using its syntax and then I would use them in select or procedures.

But recently I have found that a function is called automatically when a row is inserted or updated. Also it is accepting two parameters. This user-defined scalar function is neither called in C# through ORM and moreover there is no stored procedure using this function, yet it is being called and as per my assumption, this setting must be in a table itself. It is triggered automatically when a row is updated or inserted.

Can somebody please throw some light on this as I have never encountered it before. An example of it would really be helpful that how it is created and how we can call this function.

6
  • 2
    It could be a default value on a column of the table you are inserting into. It could also be on a trigger. Commented Apr 27, 2016 at 5:07
  • Could you please add some reference or example of something similar. It would be very helpful for me. Commented Apr 27, 2016 at 5:09
  • 2
    It might be called from the trigger. The below link might be useful. - msdn.microsoft.com/en-IN/library/ms189799.aspx Commented Apr 27, 2016 at 5:15
  • 1
    CREATE TABLE [dbo].[DEFAULTS_SAMPLE]( [ID] [int] NOT NULL, [GUID] [uniqueidentifier] NOT NULL, [CREATED] [datetime] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[DEFAULTS_SAMPLE] ADD CONSTRAINT [DF_DEFAULTS_SAMPLE_GUID] DEFAULT (newid()) FOR [GUID] GO ALTER TABLE [dbo].[DEFAULTS_SAMPLE] ADD CONSTRAINT [DF_DEFAULTS_SAMPLE_CREATED] DEFAULT (sysdatetime()) FOR [CREATED] GO Commented Apr 27, 2016 at 5:16
  • 1
    @Vincent: please do not put code samples or sample data into comments - since you cannot format it, it's extremely hard to read it.... Thank you. Commented Apr 27, 2016 at 5:40

1 Answer 1

2

You can install SQL RedGate Search (it's free) which allows you to search all SQL objects to find where your functions has been used:

http://www.red-gate.com/products/sql-development/sql-search/

enter image description here

Also possible is that you make a trace on that function to see where it has been called from (or at least by who):

How to trace T-SQL function calls

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.