zoukankan      html  css  js  c++  java
  • sql 根据外键表和外键列得到主键表和主键列的方法

    Create FUNCTION [dbo].[GetPrimaryColumn] (   -- Add the parameters for the function here  @column nvarchar(500) ) RETURNS nvarchar(max) AS

    begin  -- Add the SELECT statement with parameter references here declare @result nvarchar(max)='' select @result=(PrimaryTableName +'.'+ PrimaryColumnName)from (  SELECT   ForeignTableID   = b.fkeyid ,  ForeignTableName = '['+object_name(b.fkeyid) +']' ,  ForeignColumnID   = b.fkey ,  ForeignColumnName   ='[' + (SELECT name FROM syscolumns WHERE colid = b.fkey AND id = b.fkeyid) +']',  PrimaryTableID   = b.rkeyid ,  PrimaryTableName   = '['+object_name(b.rkeyid)+']' ,  PrimaryColumnID   = b.rkey ,  PrimaryColumnName   ='['+ (SELECT name FROM syscolumns WHERE colid = b.rkey AND id = b.rkeyid) +']' ,  CascadeUpdate   = ObjectProperty(a.id,'CnstIsUpdateCascade') ,  CascadeDelete   = ObjectProperty(a.id,'CnstIsDeleteCascade') FROM sysobjects a   join sysforeignkeys b on a.id = b.constid   join sysobjects c on a.parent_obj = c.id where a.xtype = 'f' AND c.xtype = 'U' ) FPT where (FPT.ForeignTableName +'.' +FPT.ForeignColumnName)= @column

    return @result end

    GO

  • 相关阅读:
    bootstrap之按钮和图片
    bootstrap之表单
    bootstrap之表格
    bootstrap+html5+css3
    网站链接
    linux下查看和添加PATH环境变量
    安装Memcache的PHP扩展
    ./configure
    如何学习前端?
    实战深度学习(下)OpenCV库
  • 原文地址:https://www.cnblogs.com/Mac_Hui/p/2892535.html
Copyright © 2011-2022 走看看