April 22, 2012

sp_foreignkeys (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_foreignkeys(nvarchar @table_server
, nvarchar @pktab_name
, nvarchar @pktab_schema
, nvarchar @pktab_catalog
, nvarchar @fktab_name
, nvarchar @fktab_schema
, nvarchar @fktab_catalog)

MetaData:

   
create procedure sys.sp_foreignkeys
(
@table_server sysname,
@pktab_name sysname = null,
@pktab_schema sysname = null,
@pktab_catalog sysname = null,
@fktab_name sysname = null,
@fktab_schema sysname = null,
@fktab_catalog sysname = null
)
as
select
PKTABLE_CAT = PK_TABLE_CATALOG,
PKTABLE_SCHEM = PK_TABLE_SCHEMA,
PKTABLE_NAME = PK_TABLE_NAME,
PKCOLUMN_NAME = PK_COLUMN_NAME,
FKTABLE_CAT = FK_TABLE_CATALOG,
FKTABLE_SCHEM = FK_TABLE_SCHEMA,
FKTABLE_NAME = FK_TABLE_NAME,
FKCOLUMN_NAME = FK_COLUMN_NAME,
KEY_SEQ = ORDINAL,
UPDATE_RULE =
case UPDATE_RULE
when 'CASCADE' then 0
when 'NO ACTION' then 1
when 'SET NULL' then 2
when 'SET DEFAULT' then 3
else null
end,
DELETE_RULE =
case DELETE_RULE
when 'CASCADE' then 0
when 'NO ACTION' then 1
when 'SET NULL' then 2
when 'SET DEFAULT' then 3
else null
end,
FK_NAME = convert(sysname, NULL),
PK_NAME = convert(sysname, NULL),
DEFERRABILITY = convert(smallint, null)

from
sys.fn_remote_foreign_keys (
@table_server,
@pktab_catalog,
@pktab_schema,
@pktab_name,
@fktab_catalog,
@fktab_schema,
@fktab_name)
order by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ

No comments:

Post a Comment

Total Pageviews