文档章节

代码生成器Sql Server 和 Mysql 数据库脚本

淡看江湖
 淡看江湖
发布于 2015/05/31 21:17
字数 266
阅读 256
收藏 10

#SQL SERVER
        private string SqlTableList = @"SELECT
                                                    so.name,
                                                    Convert( VARCHAR(10), ep.[value]) AS [description]
                                                FROM
                                                    sysobjects so(NOLOCK)
                                                    LEFT JOIN sys.extended_properties ep(NOLOCK) ON ep.major_id=so.id AND ep.minor_id=0
                                                WHERE 
                                                    so.[type]='U' AND so.name<>'sysdiagrams'
                                                ORDER BY
                                                    so.name";

        private string SqlFieldList = @"SELECT 
                                            c.name,
                                            t.name AS [type],
                                            c.length AS maxLength,
                                            c.isnullable AS isNullable,
                                            (
                                                SELECT COUNT(1) FROM sys.identity_columns ic(NOLOCK) WHERE ic.[object_id]=c.id AND ic.column_id=c.colid
                                            ) AS isIdentity,
                                            (
                                                SELECT VALUE FROM   sys.extended_properties ep(NOLOCK) WHERE  ep.major_id = c.id AND ep.minor_id=c.colid
                                            ) AS [description],
                                            [IsPk]=CASE WHEN EXISTS (SELECT 1 FROM sysobjects WHERE xtype='PK' and parent_obj=c.id and name IN (
                                                SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = c.id AND colid=c.colid))) THEN 1 ELSE 0 END
                                        FROM
                                            syscolumns c(NOLOCK)
                                            INNER JOIN sys.tables ts(NOLOCK) ON ts.[object_id] = c.id
                                            INNER JOIN sys.types t(NOLOCK) ON t.system_type_id=c.xtype
                                            INNER JOIN systypes st(NOLOCK) ON st.name=t.name AND st.name<>'sysname'
                                            INNER JOIN sysusers su(NOLOCK) ON st.uid=su.uid AND su.name='sys'
                                            --INNER JOIN syscolumns s(NOLOCK) ON c.[object_id]=s.id
                                        WHERE
                                            ts.name='{0}'
                                        ORDER BY
                                            c.id ASC";
     

#MySQL
        private string SqlTableList_MySql = @"SELECT
                                                TABLE_NAME as name,
                                                TABLE_COMMENT as description
                                            FROM
                                                information_schema.TABLES
                                            WHERE
                                                TABLE_SCHEMA='{0}'";

        private string SqlFieldList_MySql = @"SELECT
                                                COLUMN_NAME as name,
                                                DATA_TYPE as type,
                                                IFNULL(CHARACTER_MAXIMUM_LENGTH,0) as maxLength,
                                                (CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END) as isNullable,
as isIdentity,
                                                COLUMN_COMMENT as description,
                                                (CASE COLUMN_KEY WHEN 'PRI' THEN 1 ELSE 0 END) as IsPk
                                            FROM
                                                information_schema.COLUMNS 
                                            WHERE
                                                TABLE_SCHEMA='{0}'
                                                AND TABLE_NAME='{1}'
                                            ORDER BY
                                                ORDINAL_POSITION ASC";
        #endregion

© 著作权归作者所有

共有 人打赏支持
淡看江湖
粉丝 33
博文 82
码字总数 92173
作品 0
浦东
后端工程师
手机游戏服务器引擎Scut免费开源

scut 官网:http://www.scutgame.com/ Scut是一个开源、免费、稳定、快速开发的手机游戏服务器引擎,支持开发人员使用Python脚本语言或C#语言开发;底层采用C#编写,基于MVC框架思想设计, ...

shezjl
2015/06/16
0
0
8个不错的随机生成数据库测试数据的利器

样品/测试数据,是一种测试网络工程与应用的有效方式。除了毫无意义的数据,真实姓名,地址,邮递区号,可以使整个测试阶段比较容易。 webresourcesdepot搜集了8个很不错的免费测试数据生成器...

刘学炜
2013/05/10
0
1
PHP 对 mysql 的事务处理

mysql>mysql事务处理php代码实现事务的处理可以通过PHP预定义类mysqli的以下方法实现。 autocommit(boolean):该方法用于限定查询结果是否自动提交,如果该方法的参数为true则自动提交,如果...

罗春宗
2012/10/31
0
0
jmeter(八)-JDBC请求(sqlserver)

做JDBC请求,首先要了解这个JDBC对象是什么,然后寻找响应的数据库连接URL和数据库驱动。 数据库URL:jdbc:sqlserver://200.99.197.190:1433;databaseName=ebank 数据库驱动:com.microsoft...

劲风online
2015/01/08
0
0
RDIFramework.NET平台代码生成器V2.8发布-更新于2014-12-31(提供下载)

RDIFramework.NET平台代码生成器V2.8发布 更新于2014-12-31   RDIFramework.NET(.NET快速开发整合框架)框架做为信息化系统快速开发、整合的框架,其目的一至是给用户和开发者提供最佳的....

yonghu86
06/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

JS:异步 - 面试惨案

为什么会写这篇文章,很明显不符合我的性格的东西,原因是前段时间参与了一个面试,对于很多程序员来说,面试时候多么的鸦雀无声,事后心里就有多么的千军万马。去掉最开始毕业干了一年的Jav...

xmqywx
今天
0
0
Win10 64位系统,PHP 扩展 curl插件

执行:1. 拷贝php安装目录下,libeay32.dll、ssleay32.dll 、 libssh2.dll 到 C:\windows\system32 目录。2. 拷贝php/ext目录下, php_curl.dll 到 C:\windows\system32 目录; 3. p...

放飞E梦想O
今天
0
0
谈谈神秘的ES6——(五)解构赋值【对象篇】

上一节课我们了解了有关数组的解构赋值相关内容,这节课,我们接着,来讲讲对象的解构赋值。 解构不仅可以用于数组,还可以用于对象。 let { foo, bar } = { foo: "aaa", bar: "bbb" };fo...

JandenMa
今天
1
0
OSChina 周一乱弹 —— 有人要给本汪介绍妹子啦

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @莱布妮子 :分享水木年华的单曲《中学时代》@小小编辑 手机党少年们想听歌,请使劲儿戳(这里) @须臾时光:夏天还在做最后的挣扎,但是晚上...

小小编辑
今天
18
4
centos7安装redis及开机启动

配置编译环境: sudo yum install gcc-c++ 下载源码: wget http://download.redis.io/releases/redis-3.2.8.tar.gz 解压源码: tar -zxvf redis-3.2.8.tar.gz 进入到解压目录: cd redis-3......

hotsmile
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部