【发布时间】:2013-11-26 17:22:59
【问题描述】:
我从以下查询中得到“真”或“假”的结果。
SELECT CASE WHEN a.counter>=1 THEN 'True'
ELSE 'False' END AS isUserAuthorised
FROM (SELECT Count(*) as counter FROM information_schema.statistics
WHERE table_name = 'tblechecklistcustomer' AND index_name = 'index_Cust') a;
I want to execute the below query if the above query result is "True"
ALTER TABLE tblechecklistcustomer DROP INDEX index_Cust;
我如何在单个查询中执行此操作/使用 if 编码而不使用存储过程 我试过这种方式
SELECT CASE WHEN a.counter>=1 THEN 'True'
ELSE 'False' END AS isUserAuthorised
FROM (SELECT Count(*) as counter FROM information_schema.statistics
WHERE table_name = 'tblechecklistcustomer' AND index_name = 'index_Cust') a)=='True')
then ALTER TABLE tblechecklistcustomer DROP INDEX index_Cust;
【问题讨论】:
-
我认为这是不可能的。 DDL 语句不能放在 SELECT 查询中。
-
-
在一个过程中,我认为您可以使用检查
a.counter的IF语句和SELECT COUNT(*)子查询的结果,在THEN中使用ALTER语句条款。但是,我在编写mysql程序方面不是很有经验。 -
爱比特,为什么?
标签: mysql stored-procedures if-statement