码迷,mamicode.com
首页 > 其他好文 > 详细

生成表结构

时间:2014-12-27 12:32:34      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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

 

生成表结构

标签:

原文地址:http://www.cnblogs.com/jack-Star/p/4188139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!