Firebird 存储过程 字段信息

CREATE PROCEDURE ProGetColumnInfo(TableName varchar(50))
returns (TableCode VARCHAR(50),FIELDNAME VARCHAR(20),ID INT,TYPENAME VARCHAR(20),LEN INT,SCALE int, SUBTYPE INT,IsPrimary INT)
AS
begin
    FOR
    SELECT  a.RDB$RELATION_NAME, b.RDB$FIELD_NAME ,
    b.RDB$FIELD_ID , d.RDB$TYPE_NAME ,
    c.RDB$FIELD_LENGTH/2 , c.RDB$FIELD_SCALE,c.RDB$FIELD_SUB_TYPE,
    CASE WHEN EXISTS(select 1 FROM RDB$INDEX_SEGMENTS T1 INNER JOIN  RDB$RELATION_CONSTRAINTS T2
    ON T1.RDB$INDEX_NAME =T2.RDB$INDEX_NAME
    WHERE T2.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY'
    AND T2.RDB$RELATION_NAME = A.RDB$RELATION_NAME  AND T1.RDB$FIELD_NAME=b.RDB$FIELD_NAME)
    THEN 1 ELSE 0 END  AS IsPrimary
    FROM RDB$RELATIONS a  
    INNER JOIN RDB$RELATION_FIELDS b  ON a.RDB$RELATION_NAME = b.RDB$RELATION_NAME
    INNER JOIN RDB$FIELDS c    ON b.RDB$FIELD_SOURCE = c.RDB$FIELD_NAME
    INNER JOIN RDB$TYPES d    ON c.RDB$FIELD_TYPE = d.RDB$TYPE
    WHERE a.RDB$SYSTEM_FLAG = 0
    AND d.RDB$FIELD_NAME = 'RDB$FIELD_TYPE'  
    AND a.RDB$RELATION_NAME=:TableName
    ORDER BY a.RDB$RELATION_NAME, b.RDB$FIELD_ID
    INTO TableCode,FIELDNAME,ID,TYPENAME,LEN,SCALE, SUBTYPE,IsPrimary
    DO
    BEGIN
        suspend;
    END
END

转载于:https://www.cnblogs.com/gaoshoubuduo/archive/2012/07/19/2599571.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值