Code generator SQL Server and Mysql database scripts

Source: Internet
Author: User

A code generator is often used to record data from a script:

        #regionSql-sqlserverPrivate stringSqltablelist =@"SELECT So.name, Convert (VARCHAR), ep.[                                                     Value]) as [description] from sysobjects SO (NOLOCK) left JOIN sys.extended_properties EP (Noloc                                                      K) on ep.major_id=so.id and Ep.minor_id=0 WHERE So.                                                     [type]= ' U ' and so.name<> ' Sysdiagrams ' ORDER by So.name"; Private stringSqlfieldlist =@ " SELECT C.name, t.name as [type], C.length as MaxLength, c.isnullable A S 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 (NO                                            LOCK) 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 WHEREIndid 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        #regionSql-mysqlPrivate stringSqltablelist_mysql =@"SELECT table_name as NAME,                                                 Table_comment as description from Information_schema. TABLES WHERE table_schema= ' {0} '"; Private stringSqlfieldlist_mysql =@"SELECT column_name as NAME,                                                Data_type as TYPE, Ifnull (character_maximum_length,0) as MaxLength,                                                (Case is_nullable if ' NO ' then 0 ELSE 1 END) as isnullable,                                                 0 as Isidentity, column_comment as Description,                                            (Case Column_key "PRI" then 1 ELSE 0 END) as ISPK From INFORMATION_SCHEMA. COLUMNS WHERE table_schema= ' { 0} ' and Table_name= ' {1} ' ORDER                                                ByOrdinal_position ASC "; #endregion

Code generator SQL Server and Mysql database scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.