简体   繁体   中英

how do I make a select which always returns zero rows

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

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.

In mysql I have:

SELECT * FROM tablename LIMIT 0,0

In Intersystems caché I have:

SELECT TOP 0 * FROM tablename

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

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

Thanks in advance.

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

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

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

SELECT * FROM table_name WHERE 1 = 2;

select * from tablename where 1 != 1

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM