Re: Computed columns in temp tables
From: Jacco Schalkwijk (jacco.please.reply_at_to.newsgroups.mvps.org.invalid)
Date: 06/28/04
- Next message: Ali: "SQL Query Help!"
- Previous message: Steven Yampolsky: "Re: Computed columns in temp tables"
- In reply to: Steven Yampolsky: "Re: Computed columns in temp tables"
- Next in thread: Pablo: "Re: Computed columns in temp tables"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 28 Jun 2004 18:36:10 +0100
You can either add the function to the model database (on the basis of which
all databases are created) or you can create a start up stored procedure to
create the function in tempdb whenever SQL Server is started. The function
will not just disappear from tempdb once you have created it, only when SQL
Server is restarted, because tempdb gets recreated then.
-- Jacco Schalkwijk SQL Server MVP "Steven Yampolsky" <syampolsky@eagleinvsys.com> wrote in message news:ufdhcNTXEHA.1656@TK2MSFTNGP09.phx.gbl... > Won't that function get dropped/cleaned up and will require constant > checking for its existance? > > Steve > > "Roji. P. Thomas" <lazydragon@nowhere.com> wrote in message > news:e5MzPCSXEHA.3016@tk2msftngp13.phx.gbl... > > Create a permanent function in tempdb, like > > > > USE tempdb > > GO > > > > > > CREATE FUNCTION dbo.fnTest > > (@x int, @y int) > > RETURNS int > > AS > > BEGIN > > RETURN (@x+@y) > > END > > GO > > > > Now using another database u can call this function during temp table > > creation > > > > eg. > > > > > > USE Pubs > > > > > > CREATE TABLE #temp(x int,y int, z as dbo.fnTest(x,y)) > > > > > > INSERT INTO #temp VALUES(1,2) > > INSERT INTO #temp VALUES(3,2) > > > > SELECT * FROM #temp > > > > > > > > -- > > Roji. P. Thomas > > SQL Server Programmer > > "Steven Yampolsky" <syampolsky@eagleinvsys.com> wrote in message > > news:eLwmCwRXEHA.2940@TK2MSFTNGP09.phx.gbl... > > > How can I create a function in tempdb while inside a stored procedure? I > > > don't think I can do that. > > > > > > Lets assume I can use sp_executesql to create the function inside a SP. > > What > > > will be a lifespan of it? Will it get dropped once the session is > closed? > > > will it be accessible from other sessions? Will there be a name conflict > > > when two sessions will try and execute the same SP? > > > > > > The more I get into it, the more questions I get. Hopefully I'll come > out > > > with good knowledge! :) > > > > > > Steve > > > > > > "Jacco Schalkwijk" <jacco.please.reply@to.newsgroups.mvps.org.invalid> > > wrote > > > in message news:uCXtqSrWEHA.2520@TK2MSFTNGP12.phx.gbl... > > > > As Vyas pointed out, the issue is that you have to create the function > > in > > > > tempdb. I think he is right in suggesting that you can't use UDFs that > > > > reside in a different database in the definition of a table. > > > > > > > > > > > > > > > >
- Next message: Ali: "SQL Query Help!"
- Previous message: Steven Yampolsky: "Re: Computed columns in temp tables"
- In reply to: Steven Yampolsky: "Re: Computed columns in temp tables"
- Next in thread: Pablo: "Re: Computed columns in temp tables"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|