• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get all Table names and count for foreign key

 
Robert Jack
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used JPA and mysql.
Each table have entity h class

Table1 : student_table
----------------------------------------
studentId(PK), studentName
----------------------------------------
1 jack
2 robert
3 tom
4 cruise
----------------------------------------

Table2: roll_table
---------------------------------------------
rollId(PK), studentId(FK)
---------------------------------------------
4321 1
4322 2
4323 3
4324 4
---------------------------------------------


Table3: address_table
----------------------------------------------------
addressId(PK) City studentId(FK)
----------------------------------------------------
1 Newyork 1
2 Washington 2
3 Newyork 3
4 wahington 4
------------------------------------------------------


table4: contact_table
------------------------------------------------------------------------------
contactId(pk) phoneNumber email studentId(FK)
------------------------------------------------------------------------------



-----------------------------------------------------------------------------

Here i have 4 tables. Base table is 'student_table'. 'studentId' is primary key for this table.

The remaining 3 table have used this studentId as foreign key.
Totally 3 table contains data. one table doesn't have any data.

I need to write query for "studentId = 2 used table names and tables count if data exist other tables.

otherwise is there Any other logic to get this information.

Help me.
Thanks in advance
 
Eswar Nec
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you expect the follwing result
Now the studentId = 2 used two tables.
So you expect the result is (roll_table,address_table) and count is 2, after execute query or use any logic

Suppose contact_table have data with studentId=2,
then the result is (roll_table,address_table,contact_table) and count is 3, after execute query or any-other logic
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic