博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
代码生成器Sql Server 和 Mysql 数据库脚本
阅读量:4880 次
发布时间:2019-06-11

本文共 4375 字,大约阅读时间需要 14 分钟。

经常用到代码生成器,对于取数据脚本做个记录:

#region SQL-SqlServer        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";        #endregion        #region SQL-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,                                                0 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

 

转载于:https://www.cnblogs.com/hantianwei/p/4131119.html

你可能感兴趣的文章
sqlalchemy相关知识
查看>>
Ubuntu下搜狗输入法乱码
查看>>
计算机网络●通信协议
查看>>
爬山算法和退火算法
查看>>
再次聊一聊promise settimeout asycn awiat执行顺序---js执行机制 EVENT LOOP
查看>>
C#中怎么生成和获取GUID
查看>>
在EditPlus里配置编译和运行java代码的方法
查看>>
gson所需jar包
查看>>
window+amp搭建步骤
查看>>
最干净的pyinstaller打包成exe应用程序方法
查看>>
Python中的数据类型
查看>>
讲给普通人听的分布式数据存储【转载】
查看>>
关于最短路
查看>>
Hbase记录-zookeeper部署
查看>>
Python pexpect出现错误‘module have no attribute "spawn" 解决办法
查看>>
vs2008 C# 怎么调试C++ dll[转]
查看>>
PHP的魔术方法
查看>>
警惕麦咖啡的"缓冲区溢出保护"引起的ASP.NET 中 System.OutOfMemoryException 的错误...
查看>>
optimizer_dynamic_sampling
查看>>
HTML(WEB)开发day05
查看>>