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 |
|
kusanagirong
Starting Member
4 Posts |
Posted - 2010-07-04 : 18:54:46
|
| hi,I was trying to drop a group of table with particular conditionse.g The database has tables:AAA_1AAA_2XXX_3AAA_4AAA_5XXX_6and I only want to drop tables NOT start with XXX_but I think there is not statement (DROP TABLE ? WHERE ? NOT LIKE(...)) likeDECLARE @count INT;SET @count = SELECT COUNT(*) FROM sys.objects WHERE TYPE = 'U' AND NAME<> 'dtproperties';WHILE @count > 0BEGINDROP TABLE ? WHERE ? NOT (LIKE XXX_)SET @count = SELECT COUNT(*) FROM sys.objects WHERE TYPE = 'U' AND NAME<> 'dtproperties';ENDany1 knows how to do that?Thanks advance. |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-05 : 00:15:31
|
| One way to accomplish the task:SELECT'DROP TABLE ' +S.NAMEFROM SYSOBJECTS S WHERE XTYPE ='U' AND NAME not LIKE 'dtproperties'--To drop table not starting with 'XXX'SELECT'DROP TABLE ' +S.NAMEFROM SYSOBJECTS S WHERE XTYPE ='U' AND NAME not LIKE 'XXX%'Copy the output of the select statement and execute it.Regards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|
|