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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Deleting more than one table in SQL 7.0

Author  Topic 

admin001
Posting Yak Master

166 Posts

Posted - 2002-08-01 : 07:24:05

Hello ,

How can i delete tables in one SQL query command ; suppose for e.g deleting table starting from the letter ' AB ' or any other letter using wild cards .

Something like

select * from sysobjects and then delete tables ab*


Can i have help in building a query for such purpose rather than deleting
individual tables one by one .

Many Thanks



robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-08-01 : 07:45:56
When you say "delete table" do you mean you want to delete rows from the table, or DROP the table completely?

In any case, you can use dynamic SQL to generate the appropriate statements and then execute them:

SELECT 'DROP TABLE [' + TABLE_NAME + ']'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE 'AB%'


Run that in query analyzer and you'll get formatted SQL to perform the DROP TABLE action. Copy and paste the results into the query window and then execute it. Be aware that if you have certain constraints on the tables you cannot drop them without dropping the constraint first.

Go to Top of Page
   

- Advertisement -