zoukankan      html  css  js  c++  java
  • 生成表结构

    USE [DataInputTest]
    GO
    /****** Object:  StoredProcedure [dbo].[CreateTableList]    Script Date: 12/27/2014 11:12:37 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        <Author,,Name>
    -- Create date: <Create Date,,>
    -- Description:    <Description,,>
    -- =============================================
    ALTER PROCEDURE [dbo].[CreateTableList] 
        
    AS
    BEGIN
    
    delete from dbo.Table_Name;
    insert into dbo.Table_Name
    SELECT  NAME as  TableName 
    ,dbo.f_Primary_Keystr(name) as Primary_Key
    ,dbo.f_Field_Liststr(id) as Field_List
    ,'TMStamp' as [TimeSpan]
    , 'FinChinaData' as DataBaseName
     FROM FinChinaData.dbo.SYSOBJECTS WHERE TYPE='U' 
    order by NAME
    END
    
    
    
    USE [DataInputTest]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Field_Liststr]    Script Date: 12/27/2014 11:13:19 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER FUNCTION [dbo].[f_Field_Liststr](@id int)
    RETURNS varchar(8000)
    AS BEGIN  
    DECLARE @r varchar(8000)  
    SET @r = ''  
    SELECT @r = @r + ',' + name FROM FinChinaData.dbo.[syscolumns] WHERE id=@id 
    RETURN STUFF(@r, 1, 1, '')
    END
    
    
    USE [DataInputTest]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Primary_Keystr]    Script Date: 12/27/2014 11:13:30 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER FUNCTION [dbo].[f_Primary_Keystr](@TABLE_NAME varchar(200))
    RETURNS varchar(8000)
    AS BEGIN  
    DECLARE @r varchar(8000)  
    SET @r = ''  
    SELECT @r = @r + ',' + COLUMN_NAME  
    FROM FinChinaData.INFORMATION_SCHEMA.KEY_COLUMN_USAGE
     WHERE TABLE_NAME =@TABLE_NAME 
    RETURN STUFF(@r, 1, 1, '')
    END
  • 相关阅读:
    Ansible快速实战指南----多机自动化执行命令、部署神器
    linux 挂载共享盘
    蓄水池抽样算法
    PCA MATLAB代码
    网口转串口
    通过Python收集MySQL MHA 部署及运行状态信息的功能实现
    Linux常用命令总结(二)
    python 学习笔记 (四)
    MySQL 学习笔记(四)
    学习ProxySQL参考到几个网址
  • 原文地址:https://www.cnblogs.com/jack-Star/p/4188139.html
Copyright © 2011-2022 走看看