0

Trying to discover Foreign Keys of a table using RazorSQL, but when i use this command: EXEC SP_FKEYS <table_name> the information is always empty.

Obs: The paste of the columns table that have foreign key columns

markp-fuso
  • 28,790
  • 4
  • 16
  • 36

2 Answers2

0

NOTE: I'm assuming you're using the (Sybase) ASE product ...

If by 'foreign key' you're referring to referential integrity (RI) foreign key constraints, try:

exec sp_helpconstraint <table_name>

sp_helpconstraint will display all primary, unique, foreign key and check constraints on a table. [These constraints are created via the create table/alter table commands.]


The sp_fkeys/sp_pkeys procs are a throwback to earlier times when:

  • ASE did not have table-level RI constraints so ...

  • triggers had to be used to enforce RI requirements and therefore ...

  • sp_fkeys/sp_pkeys were used to 'document' these trigger-based RI constraints so that 3rd party apps had a means of querying the database for RI constraint details

The accuracy of the results from running sp_fkeys/sp_keys is dependent on whether or not the dbo/table owner remembers to 'document' these RI constraints.

There is no relationship between actual/enforced RI constraints (created via the create table/alter table commands) and 'documented' RI constraints (created via sp_fkeys/sp_pkeys invocations).

markp-fuso
  • 28,790
  • 4
  • 16
  • 36
  • i tried your solution, but is gives me and error: ERROR[SyBase][ODBC Driver][Adaptive Server Anywhere] Transact-SQL feature not supported Error Code : -611. – Allan Peres Jul 24 '17 at 16:21
  • According to the error message you're using the (Sybase) SQLAnywhere (aka Adaptive Server Anywhere) RDMBS product ... that's different from the ASE product (my assumption). I've edited your question's tags ... this may help flag down someone with SQLAnywhere experience that can answer your question. – markp-fuso Jul 24 '17 at 16:25
  • Thanks. I will try to search another solutions with those new informations – Allan Peres Jul 24 '17 at 16:44
0
select * from SYSFOREIGNKEYS where primary_tname='table_name'  
beater
  • 555
  • 4
  • 6