• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
reply
    Bookmark Topic Watch Topic
  • New Topic