|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Temporary TablesMy application needs to take variables from a Web form pass them to a table for my multiple Views to use. Currently I am using an already created table and doing a delete each time the application is run. I know this method can cause problems in a multi-user environment, especially when I am not locking the table. I understand that temporary tables can be created either with a # or a Declare @ (for Data Type) and these tables are automatically dropped at the end of the connection. That I can store variables from the user in these temp tables that can be used by my Views. Is the temporary table created each time a user runs the application and if so, does each user have their own temp table? Is Data Type a better way to go than #temp? Doesn't the table get stored in TempDB and will I run into the name of the table already being used condition? How / where do I create these type tables since I can't use Declare's in Views? Stored Procedure or UDF? And can I use an EXEC in a View. Thanks in advance for your assistance Views are intended only to reference only permanent tables/views. A view
cannot reference temporary tables or table variables and you can't use dynamic sql in a view. From your problem description, it seems you want to have each user session have a 'private' set of data that you can modify and query independently of other concurrent users. One technique is use a single table with a unique 'session id' that is included in all inserts and queries for a particular web session. You can delete data when the session is closed or as a separate cleanup process of expired sessions. Either stored procedures or views can be used as your database interface. Personally, I'd use procs unless you want to encapsulate joins to multiple tables in order to facilitate reuse. -- Show quoteHope this helps. Dan Guzman SQL Server MVP "Chamark" <u21870@uwe> wrote in message news:63a0a1741525b@uwe... > Using MS-SQL2000 User Level - Beginner > > My application needs to take variables from a Web form pass them to a > table > for my multiple Views to use. Currently I am using an already created > table > and doing a delete each time the application is run. I know this method > can > cause problems in a multi-user environment, especially when I am not > locking > the table. > > I understand that temporary tables can be created either with a # or a > Declare @ (for Data Type) and these tables are automatically dropped at > the > end of the connection. That I can store variables from the user in these > temp > tables that can be used by my Views. Is the temporary table created each > time > a user runs the application and if so, does each user have their own temp > table? Is Data Type a better way to go than #temp? Doesn't the table get > stored in TempDB and will I run into the name of the table already being > used > condition? > > How / where do I create these type tables since I can't use Declare's in > Views? Stored Procedure or UDF? And can I use an EXEC in a View. Thanks in > advance for your assistance > > -- > Message posted via http://www.sqlmonster.com Chamark (u21870@uwe) writes:
> My application needs to take variables from a Web form pass them to a It's not entirely clear to me: is this data stored during the session> table for my multiple Views to use. Currently I am using an already > created table and doing a delete each time the application is run. I > know this method can cause problems in a multi-user environment, > especially when I am not locking the table. that the user is active and accessed repeatedly? Or are they just data that the user enters once and then is used as input to queries? In the former case, add a session_id key to the table sa Dan said, to keep users apart. I think think this is the best solution for you. In the latter case, I don't see any need for any table at all. > I understand that temporary tables can be created either with a # or a Table variables, those with @ in the beginning lasts only for the> Declare @ (for Data Type) and these tables are automatically dropped at > the end of the connection. That I can store variables from the user in > these temp tables that can be used by my Views. Is the temporary table > created each time a user runs the application and if so, does each user > have their own temp table? Is Data Type a better way to go than #temp? > Doesn't the table get stored in TempDB and will I run into the name of > the table already being used condition? duration of the batch, so if the data is to be stored to the end of the session, table variables are not an alternative. Temp tables (names starting with #) exists until the connection is closed if they are created in the top-level scope of the connection. If they are created in a stored procedure, they go away when then procedure exits. Temp tables are local to the connection, and cannot be access by other users. I don't think temp table is a good solution for your purpose. Most applications today, and particular web applications, do not stay connected. Rather the norm is connect, issue a query, disconnect. (Behind the scenes the client API maintains a connection pool to reduce the amount of physical connection/disconnection.) To use a temp table you would have maintain a connection that stays up all the time, and this us undesireable in a web application. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx You are correct, the data is used by many queries. The user enters a
startdate and enddate in Web form, which in turn is used in the Insert command. I first clear the table(GetParams) of data. This is an ASP application DELETE FROM GetParams Where Startdate > 0 Then I do the insert data into the Getparams table. Set InsertGetparams = Server.CreateObject ("ADODB.Command") InsertGetparams.ActiveConnection = MM_MetricsCONN_STRING InsertGetparams.CommandText = "INSERT INTO Getparams (startdate, Enddate, Sitename) VALUES (?, ?, ?) " InsertGetparams.Parameters.Append InsertGetparams.CreateParameter("varSD", 200, 1, 10, MM_IIF(Request.Form("Startdate"), Request.Form("Startdate"), InsertGetparams__varSD & "")) InsertGetparams.Parameters.Append InsertGetparams.CreateParameter("varED", 200, 1, 10, MM_IIF(Request.Form("Enddate"), Request.Form("Enddate"), InsertGetparams__varED & "")) InsertGetparams.Parameters.Append InsertGetparams.CreateParameter("varSN", 200, 1, 20, MM_IIF(Request.Form("Site"), Request.Form("Site"), InsertGetparams__varSN & "")) InsertGetparams.CommandType = 1 InsertGetparams.CommandTimeout = 0 InsertGetparams.Prepared = true InsertGetparams.Execute() So if I were to use a unique session ID how do I create a unique ID each time a new user comes to the Web page and where is the ID coded in the SQL Statement? Thanks again for your help. Erland Sommarskog wrote: Show quote >> My application needs to take variables from a Web form pass them to a >> table for my multiple Views to use. Currently I am using an already >> created table and doing a delete each time the application is run. I >> know this method can cause problems in a multi-user environment, >> especially when I am not locking the table. > >It's not entirely clear to me: is this data stored during the session >that the user is active and accessed repeatedly? Or are they just data >that the user enters once and then is used as input to queries? > >In the former case, add a session_id key to the table sa Dan said, to keep >users apart. I think think this is the best solution for you. > >In the latter case, I don't see any need for any table at all. > >> I understand that temporary tables can be created either with a # or a >> Declare @ (for Data Type) and these tables are automatically dropped at >[quoted text clipped - 4 lines] >> Doesn't the table get stored in TempDB and will I run into the name of >> the table already being used condition? > >Table variables, those with @ in the beginning lasts only for the >duration of the batch, so if the data is to be stored to the end >of the session, table variables are not an alternative. > >Temp tables (names starting with #) exists until the connection is >closed if they are created in the top-level scope of the connection. If they >are created in a stored procedure, they go away when then procedure exits. >Temp tables are local to the connection, and cannot be access by other >users. > >I don't think temp table is a good solution for your purpose. Most >applications today, and particular web applications, do not stay connected. >Rather the norm is connect, issue a query, disconnect. (Behind the >scenes the client API maintains a connection pool to reduce the amount >of physical connection/disconnection.) To use a temp table you would >have maintain a connection that stays up all the time, and this us >undesireable in a web application. > -- Message posted via SQLMonster.com http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200607/1 Chamark via SQLMonster.com (u21870@uwe) writes:
> So if I were to use a unique session ID how do I create a unique ID each You will have to ask someone who knows web prorgamming, and that ain't me.> time a new user comes to the Web page But isn't there a session id you can play with? Of course, you can also use cookies, but since the user may have disabled cookies why rely on that? > and where is the ID coded in the SQL Statement? That's just one more column in the table.-- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Other interesting topics
|
|||||||||||||||||||||||