Foreign Key in RazorSQL (SyBase) with sp_fkeys

358 Views Asked by At

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

2

There are 2 best solutions below

0
beater On BEST ANSWER
select * from SYSFOREIGNKEYS where primary_tname='table_name'  
3
markp-fuso On

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).