*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
Util_FKSearch
By Jesse Roberge - YeshuaAgapao@Yahoo.com
Searches for actual and potental foreign key columns for a given primary key reference.
Generates code for creating, dropping, enabling, and disabling a FK constraint.
Also generates simple template code for merge and delete.
Also generates Util_FKSearch calls for the next lower dependency tiers.
@PKTable/@PKColumn must be a valid table/column combination or no data will be returned.
It doesn't check if @PKColumn is actually a member of a primary key or unique key constraint though.
It doesn't support composite keys, but if the one provided PK column is a member of a composite FK constraint,
it will consider it as having a FK constraint declared on it.
Requires the VIEW DATABASE STATE database permission.
Update 2009-09-21:
Added FindMode 0 to represent the PK table
Added pre-built Util_FKSearch call for the next lower tier of possible referential dependencies.
Added SimpleDelete, FKCreate, FKDrop, FKDisable, FKEnable code template output colunms
Required Input Parameters:
@PKTable VarChar(250), Table of the primary key reference
@PKColumn VarChar(250), Column of the primary key reference
Optional Input Parameters:
@PKSchema VarChar(250)='dbo', Schema of the primary key reference column's table
@FKColumn VarChar(250)='', If the FK columns might be named differently, provide this
@MaxFindMethod int How poor of a match level is permitted to be outputted
Usage:
EXECUTE Util_FKSearch @PKTable='orders', @PKColumn='order_id'
EXECUTE Util_FKSearch @PKSchema='dbo', @PKTable='orders', @PKColumn='order_id', @FKColumn='ORDERS_ORDER_ID'
Copyright:
Licensed under the L-GPL - a weak copyleft license - you are permitted to use this as a component of a proprietary database and call this from proprietary software.
Copyleft lets you do anything you want except plagiarize, conceal the source, or prohibit copying & re-distribution of this script/proc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
see <http://www.fsf.org/licensing/licenses/lgpl.html> for the license text.
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=