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 |
|
lane0618
Posting Yak Master
134 Posts |
Posted - 2002-10-21 : 19:05:14
|
| How do I convert the following statement to work in SQL? I want the fintemp1 table to be dropped only id it exists.if not fintemp1.EOFbegindrop table fintemp1endThanks,Lane |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2002-10-21 : 19:57:52
|
Something like this: CREATE TABLE #Data(ID INT)CREATE TABLE #DeleteMe(MyField VARCHAR(50))INSERT INTO #Data(ID) VALUES(1234)INSERT INTO #Data(ID) VALUES(5678)DECLARE @ID INTSET @ID = 1234--SET @ID = 1111IF (SELECT 1 FROM #Data WHERE ID = @ID) = 1 BEGIN DROP TABLE #DeleteMe ENDSELECT * from #DELETEMEDROP TABLE #Data--DROP TABLE #DELETEME <Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-10-21 : 22:33:28
|
| [q] I want the fintemp1 table to be dropped only idif it exists[/q] Your question says that you want to drop a table only if it exists.Your example drops a table if there is no data in a recordset.Not quite sure what you want, you could be looking to drop a table if it contains a certain set or if it exists.MichaelP's answers the first here is the answer to the second.You can check the existance of tables by using the INFORMATION_SCHEMA VIEWS.IF (SELECT 1FROM INFORMATION_SCHEMA.TABLESWHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = 'fintemp1') = 1BEGIN DROP TABLE fintemp1END |
 |
|
|
|
|
|