开发者

How to delete all tables with prefix "bkp" from a given database?

I have a SQL server 2005. In that server I have 3 databases -> a,b,c.

If I want to delete tables

开发者_如何转开发
  1. Tables only from database "c".
  2. The table's name should start with "bkp"
  3. Table should be created one day before.


Try this:

USE C
GO

SELECT
'DROP TABLE ' + name
FROM sys.tables
WHERE create_date >= '20101211'   -- substitute your date you're interested in
AND name like 'bkp%'

This will create as output a list of DROP TABLE:.... statement - copy those and paste them into a new SSMS window and execute those - and you're done!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜