Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Delete Tables with Certain Condition

Hi All,

I want to delete (drop) tables with certain condition.

How could I do it?

Thank you.
Avatar of RiteshShah
RiteshShah
Flag of India image

declare @d int
set @d=5
if @d>0
begin
    drop table tableName
end
else
begin
    print 'can not drop'
end

you can delete the data by using where clause..whar r u looking exactly??can you an example??


DELETE FROM customer
WHERE customer_name = 'IBM'

Open in new window

@shivkasi,

have you read Author's statement?

>>I want to delete (drop) tables with certain condition.<<

he want to drop table, not delete records. which could be done by the way I saw or this one:



if exists(select 1 from TableName where Field1='SomeCondition')
begin
   drop table tableName
end
else
begin
   print 'can not drop'
end

Open in new window

Avatar of krisdigitx
krisdigitx

try using bash/php, you can put conditions there
Avatar of emi_sastra

ASKER

Hi All,

I am sorry, it seems that my description was not clear enough.

Suppose in my database I have tables below:

1. THSJPOJUAL1003
2. THSJPOJUAL1050
3. so on..

I want to delete tables where its name not less than THSJPOJUAL2000.

How could I do it?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of lammy82
lammy82
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi lammy82,

That's great.

My problem is solved.

Thank you very much for your help.