从Word中拷贝字段用于MySQL建表

1.SQL 基础表 建立

USE [Test]
GO

/****** Object:  Table [dbo].[CreateTable]    Script Date: 10/17/2016 14:07:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[CreateTable](
    [field] [nvarchar](50) NULL,
    [fielddesc] [nvarchar](150) NULL,
    [type] [nvarchar](50) NULL,
    [note] [nvarchar](190) NULL
) ON [PRIMARY]

GO


USE [Test]
GO

/****** Object:  Table [dbo].[CreateTableDefault]    Script Date: 10/17/2016 14:07:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[CreateTableDefault](
    [field] [nvarchar](50) NULL,
    [fielddesc] [nvarchar](50) NULL,
    [type] [nvarchar](50) NULL,
    [note] [nvarchar](50) NULL
) ON [PRIMARY]

GO
View Code

2.打开编辑 CreateTable,从Word里面拷贝对应信息,复制过去

3.生成字段信息

SELECT  '`' + field + '`' + ' ' + type + ( CASE WHEN field = 'ID' THEN '  COMMENT  '''
                                                ELSE ' DEFAULT NULL COMMENT '''
                                           END ) 
        + fielddesc + ' ' + ISNULL(note, '') + ' ''' + ','
FROM    dbo.CreateTable
UNION ALL
SELECT  '`' + field + '`' + ' ' + type + ' DEFAULT NULL COMMENT '''
        + fielddesc + ' ' + ISNULL(note, '') + ' ''' + ','
FROM    dbo.CreateTableDefault
View Code

4.组合信息

posted @ 2016-10-17 14:09  maanshancss  阅读(483)  评论(0编辑  收藏  举报