生成表结构

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

 

你可能感兴趣的:(表结构)