首页 > 代码库 > 生成表结构

生成表结构

USE [DataInputTest]GO/****** Object:  StoredProcedure [dbo].[CreateTableList]    Script Date: 12/27/2014 11:12:37 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:        <Author,,Name>-- Create date: <Create Date,,>-- Description:    <Description,,>-- =============================================ALTER PROCEDURE [dbo].[CreateTableList]     ASBEGINdelete from dbo.Table_Name;insert into dbo.Table_NameSELECT  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 NAMEENDUSE [DataInputTest]GO/****** Object:  UserDefinedFunction [dbo].[f_Field_Liststr]    Script Date: 12/27/2014 11:13:19 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER 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, ‘‘)ENDUSE [DataInputTest]GO/****** Object:  UserDefinedFunction [dbo].[f_Primary_Keystr]    Script Date: 12/27/2014 11:13:30 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER 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

 

生成表结构