• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get all Table names and count for foreign key

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic