Code generator SQL Server and Mysql database scripts

Source: Internet
Author: User
Tags generator

#SQL SERVER
private string sqltablelist = @ "Select
So.name,
Convert (VARCHAR), 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 if ' NO ' then 0 ELSE 1 END) as isnullable,
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 by
Ordinal_position ASC ";
#endregion

Code generator SQL Server and Mysql database scripts

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.