![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#2
| |||
| |||
|
|
Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#3
| |||
| |||
|
|
Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#4
| |||
| |||
|
|
Yes that's can be true depending on how and where he creates them. I was assuming (Probably shouldn't have) that they created the temp table in sp's called from an outer one similar to this: create proc test1 as select * into #t from orders where 1 = 2 SELECT * FROM #t GO exec test1 select * from #t So Jay in that case the temp table is dropped at the end of the batch but if you did CREATE TABLE #t (...) before calling the sp's it would exist until the end of the session as Kalen suggested. Thank's for pointing that out Kalen. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:u3NbANdZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#5
| |||
| |||
|
|
Yes, temp tables created in a sp have a lifespan of the sp. But that is still not the same as a batch. You can have multiple proc calls in a single batch. A batch is a very specific construct in SQL Server, but doesn't affect the scope or lifespan of temp table. (A batch does however affect the scope of a local variable.) -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:eJO9M#dZDHA.2284 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes that's can be true depending on how and where he creates them. I was assuming (Probably shouldn't have) that they created the temp table in sp's called from an outer one similar to this: create proc test1 as select * into #t from orders where 1 = 2 SELECT * FROM #t GO exec test1 select * from #t So Jay in that case the temp table is dropped at the end of the batch but if you did CREATE TABLE #t (...) before calling the sp's it would exist until the end of the session as Kalen suggested. Thank's for pointing that out Kalen. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:u3NbANdZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#6
| |||
| |||
|
|
Ahhh, yes of coarse you are correct. I shouldn't have used the term "Batch" in that manner. Sorry for the confusion and thanks for the correction Kalen.. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:ej8tTLeZDHA.2020 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes, temp tables created in a sp have a lifespan of the sp. But that is still not the same as a batch. You can have multiple proc calls in a single batch. A batch is a very specific construct in SQL Server, but doesn't affect the scope or lifespan of temp table. (A batch does however affect the scope of a local variable.) -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:eJO9M#dZDHA.2284 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes that's can be true depending on how and where he creates them. I was assuming (Probably shouldn't have) that they created the temp table in sp's called from an outer one similar to this: create proc test1 as select * into #t from orders where 1 = 2 SELECT * FROM #t GO exec test1 select * from #t So Jay in that case the temp table is dropped at the end of the batch but if you did CREATE TABLE #t (...) before calling the sp's it would exist until the end of the session as Kalen suggested. Thank's for pointing that out Kalen. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:u3NbANdZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#7
| |||
| |||
|
|
Thank you both for the information. A lot has been cleared up. :-) I plan to create the temp table from an ASP.NET application. When the user is finished with the application, is it safe to assume that the temp table will be removed? Thanks again!!! - J "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:uV2IAXeZDHA.2020 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Ahhh, yes of coarse you are correct. I shouldn't have used the term "Batch" in that manner. Sorry for the confusion and thanks for the correction Kalen.. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:ej8tTLeZDHA.2020 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes, temp tables created in a sp have a lifespan of the sp. But that is still not the same as a batch. You can have multiple proc calls in a single batch. A batch is a very specific construct in SQL Server, but doesn't affect the scope or lifespan of temp table. (A batch does however affect the scope of a local variable.) -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:eJO9M#dZDHA.2284 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes that's can be true depending on how and where he creates them. I was assuming (Probably shouldn't have) that they created the temp table in sp's called from an outer one similar to this: create proc test1 as select * into #t from orders where 1 = 2 SELECT * FROM #t GO exec test1 select * from #t So Jay in that case the temp table is dropped at the end of the batch but if you did CREATE TABLE #t (...) before calling the sp's it would exist until the end of the session as Kalen suggested. Thank's for pointing that out Kalen. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:u3NbANdZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
#8
| |||
| |||
|
|
That depends on what the user does when he is finished. It is usually best not to assume anything if you can do something to take out those assumptions. It's not a lot of code to drop the table when your finished with it. IF OBJECT_ID('tempdb..#YourTable') IS NOT NULL DROP TABLE #YourTable But if the user drops the connection and it is not being pooled (or is and is properly cleaned up) then yes it will be dropped. Otherwise no. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:e5rUMkfZDHA.2464 (AT) TK2MSFTNGP09 (DOT) phx.gbl... Thank you both for the information. A lot has been cleared up. :-) I plan to create the temp table from an ASP.NET application. When the user is finished with the application, is it safe to assume that the temp table will be removed? Thanks again!!! - J "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:uV2IAXeZDHA.2020 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Ahhh, yes of coarse you are correct. I shouldn't have used the term "Batch" in that manner. Sorry for the confusion and thanks for the correction Kalen.. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:ej8tTLeZDHA.2020 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes, temp tables created in a sp have a lifespan of the sp. But that is still not the same as a batch. You can have multiple proc calls in a single batch. A batch is a very specific construct in SQL Server, but doesn't affect the scope or lifespan of temp table. (A batch does however affect the scope of a local variable.) -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:eJO9M#dZDHA.2284 (AT) TK2MSFTNGP10 (DOT) phx.gbl... Yes that's can be true depending on how and where he creates them. I was assuming (Probably shouldn't have) that they created the temp table in sp's called from an outer one similar to this: create proc test1 as select * into #t from orders where 1 = 2 SELECT * FROM #t GO exec test1 select * from #t So Jay in that case the temp table is dropped at the end of the batch but if you did CREATE TABLE #t (...) before calling the sp's it would exist until the end of the session as Kalen suggested. Thank's for pointing that out Kalen. -- Andrew J. Kelly SQL Server MVP "Kalen Delaney" <replies (AT) public_newsgroups (DOT) com> wrote in message news:u3NbANdZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Actually, #temp tables exist for the duration of the session, not just for the batch. So to answer the original question, when the user logs out, the session is terminated, so the temp table disappears. -- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Andrew J. Kelly" <sqlmvpnooospam (AT) shadhawk (DOT) com> wrote in message news:#ymf7EdZDHA.656 (AT) tk2msftngp13 (DOT) phx.gbl... Any local temp tables (ones created as #something) are automatically dropped when the batch is done. If you use a CREATE TABLE Tempdb..xxxx the table will stay there as long as the server does not get restarted. But then if 2 people call the same procedure your hosed. That's what LOCAL temp tables are for. They are unique for each user so others won't see them. In either case having such a dependency is really a poor design and you might want to take this opportunity to redo this logic. -- Andrew J. Kelly SQL Server MVP "Jay" <jerry280 (AT) yahoo (DOT) com> wrote in message news:%23XMTSjcZDHA.2632 (AT) TK2MSFTNGP12 (DOT) phx.gbl... Hello everyone, I am in the process of converting an old Access database to SQL2000 to run on a new application but the database table structure must not change. My problem is many of the queries depend on the results of many other queries which are stored in temporary tables. This was not a problem when it was used by one user but now it's to be used by 107 users. I looked a little bit into the TEMPDB option but I'm not too clear how that works. If a certain user is running reports and the queries create tables in the TEMPDB, are those tables automatically removed when the user logs out of the system? If not, is there some sort of batch process where SQL2000 can delete tables from the TEMPDB that are over 2 days old? Thank you and I apologize for my ignorance. I'm very new at using MSSQL. - J |
![]() |
| Thread Tools | |
| Display Modes | |
| |