如何进行总是返回零行的选择

时间:2021-10-13 09:08:29

I want to determine if a column exists in a table for any jdbc driver.

我想确定任何jdbc驱动程序的表中是否存在列。

In order to know the columns in a table, I have to make a query to the table and then get the ResultSetMetaData for the info, but this is pretty expensive in like 99% of times.

为了知道表中的列,我必须对表进行查询,然后获取信息的ResultSetMetaData,但这在99%的时间内非常昂贵。

In mysql I have:

在mysql我有:

SELECT * FROM tablename LIMIT 0,0

SELECT * FROM tablename LIMIT 0,0

In Intersystems caché I have:

在Intersystems的caché我有:

SELECT TOP 0 * FROM tablename

SELECT TOP 0 * FROM tablename

But, for example, in JavaDB I cannot apply any limit at all.

但是,例如,在JavaDB中,我根本不能应用任何限制。

Is there any generic query that would give me the same result and still be fair with the DB performance?

是否有任何通用查询可以给我相同的结果并且仍然可以公平地使用DB性能?

Thanks in advance.

提前致谢。

5 个解决方案

#1


SELECT * FROM tableName WHERE 'You' = 'Smart'

#2


...or you could just use the DatabaseMetaData route.

...或者您可以使用DatabaseMetaData路由。

There's a "getColumns" method that does what you need without creating a resultset.

有一个“getColumns”方法可以在不创建结果集的情况下完成所需的操作。

#3


SELECT * FROM table_name WHERE 1 = 2;

SELECT * FROM table_name WHERE 1 = 2;

#4


select * from tablename where 1 != 1

#5


Unrelated, but if you just need the columns in MySQL, you can run SHOW FIELDS FROM tablename. This returns columns and the associated info.

不相关,但如果您只需要MySQL中的列,则可以运行SHOW FIELDS FROM tablename。这将返回列和相关信息。

#1


SELECT * FROM tableName WHERE 'You' = 'Smart'

#2


...or you could just use the DatabaseMetaData route.

...或者您可以使用DatabaseMetaData路由。

There's a "getColumns" method that does what you need without creating a resultset.

有一个“getColumns”方法可以在不创建结果集的情况下完成所需的操作。

#3


SELECT * FROM table_name WHERE 1 = 2;

SELECT * FROM table_name WHERE 1 = 2;

#4


select * from tablename where 1 != 1

#5


Unrelated, but if you just need the columns in MySQL, you can run SHOW FIELDS FROM tablename. This returns columns and the associated info.

不相关,但如果您只需要MySQL中的列,则可以运行SHOW FIELDS FROM tablename。这将返回列和相关信息。