I have table as follow ::
id || name || Desg || Sal || deptId
1 ||ajay ||MD ||999 ||1
2 ||Kaushal ||Engg ||100 ||2
3 ||Vidhi ||HR ||5000 ||3
4 ||Sonu ||SSP ||200 ||1
5 ||Jay ||Asst Manager ||120 ||3
6 ||Uvi ||Utra ||450 ||5
id is primary column. This is just one table with name person.
I want to get the values of primary key column (here id).
My java method will receives the table name & where clause and will return the ArrayList of values of primary Column. Now the problem is that based on table name it should be decided which column is primary column. Is there any query which can give values ::
<<Part of Query to get values of primary column key>> where sal > 150 & deptId != 1 (Where clause that method will receive)
Database metadata can be extracted from the
INFORMATION_SCHEMAtables, as documented here.I think the table you’d be looking at would be
columns:although that’s only for a simplistic case.
For proper index analysis, the
statisticstable can be consulted. From (somewhat vague) memory, the index name or type can be used to figure out if the index is a primary key index.Once you have the primary key column name, you can simply construct another query based on that.
In other words (untested):
then execute
newQuery.