如何删除在1月10日之前创建的用户名下的所有表? [英] How to drop all tables under a username which were created before jan 1,2010?

查看:71
本文介绍了如何删除在1月10日之前创建的用户名下的所有表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除在2010年1月1日之前创建的所有表。我在stackoverflow中遇到了一些示例,但没有一个符合我的需要。与主键没有冲突,这是一个好点。它必须在pl / sql中,但sql是可以的,我可以搞清楚。



我尝试过:



从用户中删除user_table

从用户创建的drop user_table< '01 -jan-2010';

解决方案

它将依赖于数据库系统,所以SQL就行了对它没什么帮助。

获取表创建日期不是问题,对于MS SQL,它是:

  SELECT  [name],create_date  FROM  sys.tables 



而对于Oracle而言则不同: oracle - 如何在SQL中检查表的创建日期? - 堆栈溢出 [ ^ ]

但是DROP TABLES命令没有WHERE子句,因此您需要使用该查询的结果来构建SQL DROP将TABLE命令作为NVARCHAR字符串并使用EXEC执行删除。



我没有编写该代码:我没有要删除的表格进行测试! :笑:


I need to drop all table that were created before jan 1st 2010. I have came across some example here at stackoverflow but none meets my need.There is no conflict with primary key which is a good point. It has to be in pl/sql but sql is ok, I can figure it out.

What I have tried:

drop user_table from user
drop user_table from user created <'01-jan-2010';

解决方案

It's going to be dependant on the DB system, so "SQL is OK" isn't going to help much.
Getting the table creation date isn't a problem, for MS SQL it's:

SELECT [name], create_date FROM sys.tables


And for Oracle it's different: oracle - how to check the creation date of tables in SQL? - Stack Overflow[^]
But the DROP TABLES command doesn't have a WHERE clause, so you will need to use the results of that query to build an SQL DROP TABLE command as a NVARCHAR string and use EXEC to perform the delete.

I'm not writing that code: I have no tables I want to drop for testing! :laugh:


这篇关于如何删除在1月10日之前创建的用户名下的所有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆