代碼產生器Sql Server 和 Mysql 資料庫指令碼

來源:互聯網
上載者:User

標籤:des   style   blog   io   ar   color   os   sp   for   

經常用到代碼產生器,對於取資料指令碼做個記錄:

        #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

 

代碼產生器Sql Server 和 Mysql 資料庫指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.