Gets the primary key column name of the table SQL
SELECT * FROM User_cons_columns
where constraint_name = (select Constraint_name from user_constraints
WHERE table_name = ' bst_favorite ' and constraint_type = ' P ');
Remember : table names are capitalized
Perform the test, the table all the primary keys are detected, the primary key column name is in the fourth column
Get all column names for a table SQL
SELECT * FROM table_name where rownum=1
This SQL statement believes everyone knows what it means.
Using JDBC programming to check the primary key column name, can be queried by the first statement above.
There is also a way to query the table's primary key column names, using JDBC Programming, the code is as follows:
DatabaseMetaData dbmd= conn.getmetadata ();
rs = Dbmd.getprimarykeys (Null,null,tablename.touppercase ()); To capitalize the table name to properly remove the primary key
while (Rs.next ()) {
Columnname=rs.getstring (4);
System.out.println (ColumnName);
}
Use JDBC to get all the column names of the table, or through the second SQL statement above, the code is as follows:
String sql= "SELECT * FROM table_name where rownum=1";
Stm=conn.createstatement ();
Rs=stm.executequery (SQL);
Rs.next ();
ResultSetMetaData Metadata=rs.getmetadata ();
for (int i=1;i<=metadata.getcolumncount (); i++) {
System.out.println (Metadata.getcolumnname (i)); }
How Oracle Gets the primary key column name of the table and how to get all the column names of the table