Create Table using a user defined function

Create Table using a user defined function

Post by Sreedha » Fri, 20 Dec 2002 00:14:27



Hi,
  Can any body let me know how to create a table with a
user defined function i.e., while inserting values into
table the value should be changed by the function and
inserted into the table.

for example:

Create Table mytable
(keyid int not null,
  mydata
  (dbo.fn_encryptPassword(mydata))
)

i.e., i want to update the current column value.

If not possible let me know what is the other ways i can
do it.

Thanks in advance..
Sreedhar.

 
 
 

Create Table using a user defined function

Post by Anith Se » Fri, 20 Dec 2002 00:29:57


In SQL 2000, you can use a UDF as a computed column expression.


RETURNS INT
AS
BEGIN



END
GO

CREATE TABLE tbl
         (keyCol INT NOT NULL PRIMARY KEY,
          dataCol INT NOT NULL,
          encryptedCol AS dbo.fn_encryptPassword(dataCol))
GO

Note that all restrictions for the computed columns apply to the
evaluated expression. See SQL Server Books Online for details

--
- Anith
(Please respond only to newsgroups)