Home All Groups Group Topic Archive Search About

Default Constraints (call: User-Defined Function or proc)

Author
24 Sep 2005 4:17 AM
ReTF
Hi
Have any way to call User-Defined Function or proc of a Default Constraint??

INT CONSTRAINT test_df DEFAULT dbo.myFunc()

Thaks

Author
24 Sep 2005 4:44 AM
Jerry Spivey
According to the SQL BOL, a user-defined function can be used in a DEFAULT
clause.  A stored procedure - not that I am aware of.

HTH

Jerry
Show quote
"ReTF" <re.tf@newsgroup.nospam> wrote in message
news:%23hlZz7LwFHA.624@TK2MSFTNGP11.phx.gbl...
> Hi
> Have any way to call User-Defined Function or proc of a Default
> Constraint??
>
> INT CONSTRAINT test_df DEFAULT dbo.myFunc()
>
> Thaks
>
Author
24 Sep 2005 2:43 PM
John Bell
Hi

Here is an example of a udf:

CREATE FUNCTION SetDate ()
RETURNS Datetime
AS
BEGIN
DECLARE @Startdate Datetime
SET @Startdate = '20050101'
RETURN @Startdate
END

CREATE TABLE MyTest ( id int not null identity(1,1) Primary key,
name varchar(10) NOT NULL,
StartDate datetime not null default dbo.SetDate(),
EndDate datetime not null default getdate()+1
)

INSERT INTO MyTest ( name ) VALUES ( 'John')

SELECT * FROM MyTest
/*
id          name       StartDate
EndDate
----------- ---------- ------------------------------------------------------
---------------------------1           John       2005-01-01 00:00:00.000
2005-09-25 15:38:48.220

(1 row(s) affected)
*/

John




Show quote
"ReTF" <re.tf@newsgroup.nospam> wrote in message
news:%23hlZz7LwFHA.624@TK2MSFTNGP11.phx.gbl...
> Hi
> Have any way to call User-Defined Function or proc of a Default
> Constraint??
>
> INT CONSTRAINT test_df DEFAULT dbo.myFunc()
>
> Thaks
>

AddThis Social Bookmark Button