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 |
cyberpd
Yak Posting Veteran
60 Posts |
Posted - 2007-08-22 : 01:30:28
|
I want to delete all the rows from my table stockReport, within a stored procedure.When the SP runs I just need to check if the table exists in the database or not.if the table exists then there will be Delete from stockReport, otherwise nothing will happen.plz help me with this query.thanks and regards |
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2007-08-22 : 01:46:41
|
hi you can use if exists(select * from sysobjects where xtype = 'U' and name = 'stockReport')begindelete from stockReportend |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 01:50:00
|
If you want to delete all rows you can truncate it alsoIf exists(select * from sysobjects where xtype='u' and name='table_name')truncate table table_nameMadhivananFailing to plan is Planning to fail |
 |
|
cyberpd
Yak Posting Veteran
60 Posts |
Posted - 2007-08-22 : 01:58:56
|
wow, that was fast..thanks, that was exactly what i wanted...i am stupid as i was going to use the following..IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLESWHERE TABLE_NAME = 'tmpSTOCKREPORT')BEGIN DELETE FROM tmpSTOCKREPORTEND |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 02:51:37
|
As I said, if you want to delete all rows use truncateMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|