Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
olily
Starting Member
37 Posts |
Posted - 2002-05-12 : 19:50:58
|
| I have about 40 tables per day in tempdb which I would like to housekeep by writing a sql script or a vb program to automate the process. The problem is I do not know the table name. I can identify the name by Type=User and my table name format is tmp_mmddyyhhmmss. I'm using Sql Server 7.0 and VB6. |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-05-13 : 00:34:11
|
no problems olily- check out Books-On-Line (BOL) under INFORMATION_SCHEMA.You might want something likeselect *from INFORMATION_SCHEMA.TABLESwhere table_name like 'tmp%'etcThen just build your SQL Strings - eg to delete all your temp tables more than 1 day old you could do something like:SQL = "select table_name from information_schema.tables "SQL = SQL & "where datediff(dd,CONVERT(datetime, SUBSTRING(@TABLE_NAME,5,2)+'-'+SUBSTRING(@TABLE_NAME,7,2)+'-'+SUBSTRING(@TABLE_NAME,9,2), 10),getdate()) > 1"rst.Open SQL, CnxnDo while Not rst.EOF dropTableSQL = "drop table " & rst.Fields("TABLE_NAME") rst1.Open dropTableSQL, Cnxn...etc etc....LoopOf course you'll need to tidy that up abit - I'd probably make a view which returns the tables you want to delete, to make your string concatenation easier etc etcHTH --I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
olily
Starting Member
37 Posts |
Posted - 2002-05-14 : 00:48:50
|
| Thanks! This really make my work easier! |
 |
|
|
|
|
|
|
|