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